Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
get rid of #py2 outside of explain_pickle
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Mar 20, 2022
1 parent 55a711e commit 683eed9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 113 deletions.
29 changes: 15 additions & 14 deletions src/sage/groups/perm_gps/permgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,25 +1585,26 @@ def orbit(self, point, action="OnPoints"):
Action of `S_4` (on a nonstandard domain) on tuples of sets::
sage: S4 = PermutationGroup([ [('c','d')], [('a','c')], [('a','b')] ])
sage: S4.orbit((('a','c'),('b','d')),"OnTuplesSets") # py2
(({'a', 'c'}, {'b', 'd'}),
({'a', 'd'}, {'c', 'b'}),
({'c', 'b'}, {'a', 'd'}),
({'b', 'd'}, {'a', 'c'}),
({'c', 'd'}, {'a', 'b'}),
({'a', 'b'}, {'c', 'd'}))
sage: orb = S4.orbit((('a','c'),('b','d')),"OnTuplesSets")
sage: expect = (({'a', 'c'}, {'b', 'd'}), ({'a', 'd'}, {'c', 'b'}),
....: ({'c', 'b'}, {'a', 'd'}), ({'b', 'd'}, {'a', 'c'}),
....: ({'c', 'd'}, {'a', 'b'}), ({'a', 'b'}, {'c', 'd'}))
sage: expect == orb
True
Action of `S_4` (on a very nonstandard domain) on tuples of sets::
sage: S4 = PermutationGroup([ [((11,(12,13)),'d')],
....: [((12,(12,11)),(11,(12,13)))], [((12,(12,11)),'b')] ])
sage: S4.orbit((( (11,(12,13)), (12,(12,11))),('b','d')),"OnTuplesSets") # py2
(({(11, (12, 13)), (12, (12, 11))}, {'b', 'd'}),
({'d', (12, (12, 11))}, {(11, (12, 13)), 'b'}),
({(11, (12, 13)), 'b'}, {'d', (12, (12, 11))}),
({(11, (12, 13)), 'd'}, {'b', (12, (12, 11))}),
({'b', 'd'}, {(11, (12, 13)), (12, (12, 11))}),
({'b', (12, (12, 11))}, {(11, (12, 13)), 'd'}))
sage: orb = S4.orbit((( (11,(12,13)), (12,(12,11))),('b','d')),"OnTuplesSets")
sage: expect = (({(11, (12, 13)), (12, (12, 11))}, {'b', 'd'}),
....: ({'d', (12, (12, 11))}, {(11, (12, 13)), 'b'}),
....: ({(11, (12, 13)), 'b'}, {'d', (12, (12, 11))}),
....: ({(11, (12, 13)), 'd'}, {'b', (12, (12, 11))}),
....: ({'b', 'd'}, {(11, (12, 13)), (12, (12, 11))}),
....: ({'b', (12, (12, 11))}, {(11, (12, 13)), 'd'}))
sage: all(x in orb for x in expect) and len(orb) == len(expect)
True
"""
from sage.sets.set import Set

Expand Down
97 changes: 0 additions & 97 deletions src/sage/misc/lazy_attribute.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -332,103 +332,6 @@ class lazy_attribute(_lazy_attribute):
TESTS:
.. rubric:: Partial support for old style classes
Old style and new style classes play a bit differently with
@property and attribute setting::
sage: class A: # py2 - no old-style classes on python 3
....: @property
....: def x(self):
....: print("calculating x")
....: return 3
....:
sage: a = A() # py2
sage: a.x = 4 # py2
sage: a.__dict__ # py2
{'x': 4}
sage: a.x # py2
4
sage: a.__dict__['x']=5 # py2
sage: a.x # py2
5
sage: class A (object):
....: @property
....: def x(self):
....: print("calculating x")
....: return 3
....:
sage: a = A()
sage: a.x = 4
Traceback (most recent call last):
...
AttributeError: can...t set attribute...
sage: a.__dict__
{}
sage: a.x
calculating x
3
sage: a.__dict__['x']=5
sage: a.x
calculating x
3
In particular, lazy_attributes need to be implemented as non-data
descriptors for new style classes, so as to leave access to
setattr. We now check that this implementation also works for old
style classes (conditional definition does not work yet)::
sage: class A:
....: def __init__(self):
....: self.a=2 # just to have some data to calculate from
....:
....: @lazy_attribute
....: def x(self):
....: print("calculating x")
....: return self.a + 1
....:
sage: a = A()
sage: a.__dict__
{'a': 2}
sage: a.x
calculating x
3
sage: a.__dict__
{'a': 2, 'x': 3}
sage: a.x
3
sage: timeit('a.x') # random
625 loops, best of 3: 115 ns per loop
sage: a = A()
sage: a.x = 4
sage: a.x
4
sage: a.__dict__
{'a': 2, 'x': 4}
sage: class B(A):
....: @lazy_attribute
....: def x(self):
....: if hasattr(self, "y"):
....: print("calculating x from y in B")
....: return self.y
....: else:
....: print("y not there; B does not define x")
....: return NotImplemented
....:
sage: b = B()
sage: b.x # todo: not implemented
y not there; B does not define x
calculating x in A
3
sage: b = B()
sage: b.y = 1
sage: b.x
calculating x from y in B
1
.. rubric:: Lazy attributes and Cython
This attempts to check that lazy attributes work with built-in
Expand Down
4 changes: 2 additions & 2 deletions src/sage/structure/factory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ cdef class UniqueFactory(SageObject):
even though the "factory data" are now available (this is not the case
on Python 3 which *only* has new style classes)::
sage: loads(dumps(d)) is d # py2
False
sage: loads(dumps(d)) is d
True
sage: d._factory_data
(<__main__.MyFactory object at ...>,
(...),
Expand Down

0 comments on commit 683eed9

Please sign in to comment.