Opened 9 years ago
Closed 6 years ago
#15994 closed enhancement (fixed)
Python 3 preparation: Change for removed members of types module
Reported by:  Wilfried Luebbe  Owned by:  

Priority:  major  Milestone:  sage8.0 
Component:  python3  Keywords:  python3 
Cc:  Merged in:  
Authors:  Jeroen Demeyer  Reviewers:  Frédéric Chapoton 
Report Upstream:  N/A  Work issues:  
Branch:  925b5a5 (Commits, GitHub, GitLab)  Commit:  925b5a585d6f053849ffa16a0d5329eedec015ad 
Dependencies:  Stopgaps: 
Description
Some members were removed from the types
module in Python 3.
Replace the deprecated members by their modern equivalents.
Changes according to lib2to3/fixes/fix_types.py
:
'BooleanType' : 'bool', 'BufferType' : 'memoryview', 'ClassType' : 'type', 'ComplexType' : 'complex', 'DictType': 'dict', 'DictionaryType' : 'dict', 'EllipsisType' : 'type(Ellipsis)', 'FloatType': 'float', 'IntType': 'int', 'ListType': 'list', 'LongType': 'int', 'ObjectType' : 'object', 'NoneType': 'type(None)', 'NotImplementedType' : 'type(NotImplemented)', 'SliceType' : 'slice', 'StringType': 'bytes', # XXX ? 'StringTypes' : 'str', # XXX ? 'TupleType': 'tuple', 'TypeType' : 'type', 'UnicodeType': 'str', 'XRangeType' : 'range',
This ticket is tracked as a dependency of metaticket ticket:15980.
Attachments (1)
Change History (30)
Changed 9 years ago by
Attachment:  faileddoctests15994.log added 

comment:1 Changed 9 years ago by
Branch:  → u/wluebbe/ticket/15994 

Commit:  → f741ed21b0019f1d6e1119bdd2038a337f7174cc 
The generated code leads to 8 doctest failures, all of them in src/sage/misc/explain_pickle.py
.
For details see the attachment.
New commits:
f741ed2  changes generated by 2to3 tool (types) for Python 3

comment:2 Changed 9 years ago by
There is a Python ticket 2to3 doesn't convert 'types.InstanceType' to 'object'.
The recommendation seems to be
or add try: from types import InstanceType except ImportError: InstanceType = object to the top of the module; this would then work for both 2.x and 3.x (assuming that replacing InstanceType with object is actually correct in the code in question).
comment:3 Changed 9 years ago by
Status:  new → needs_review 

Status updated to allow "needs work" ...
comment:4 Changed 9 years ago by
Status:  needs_review → needs_work 

It needs work on the failing doctests.
The failing tests seem all to be concerned with old style classes. Python 3 has only new style classes.
Maybe there are no more old style classes in Sage  and those tests might be removed??
Is there somebody familiar with src/sage/misc/explain_pickle.py
who can comment?
comment:5 Changed 9 years ago by
There are plenty of old style classes in Sage. A lot of the codebase is ancient and has not received much attention in years. I don't know the module at all, so I can't really help here.
comment:6 Changed 9 years ago by
Milestone:  sage6.2 → sage6.3 

comment:7 Changed 8 years ago by
Milestone:  sage6.3 → sage6.4 

comment:8 Changed 7 years ago by
Branch:  u/wluebbe/ticket/15994 → public/15994 

Commit:  f741ed21b0019f1d6e1119bdd2038a337f7174cc → 02b3dedb16ae9f770bc9b0bb88ef6664be58f68a 
comment:9 Changed 7 years ago by
Milestone:  sage6.4 → sage7.2 

comment:10 Changed 7 years ago by
Authors:  → Wilfried Luebbe 

Status:  needs_work → needs_review 
I am temporarily putting this to needs review to see what are the errors now.
comment:11 Changed 7 years ago by
Commit:  02b3dedb16ae9f770bc9b0bb88ef6664be58f68a → 50c9d97351049f66ac17ba52b8635428eef95418 

Branch pushed to git repo; I updated commit sha1. New commits:
50c9d97  trac #15994 changing doctests in explain_pickle

comment:12 Changed 7 years ago by
Status:  needs_review → needs_work 

If somebody with expertise in pickles could have a look, that would be great.
comment:13 Changed 7 years ago by
Component:  distribution → python3 

comment:15 Changed 7 years ago by
Milestone:  sage7.2 → sage7.3 

comment:16 Changed 7 years ago by
There remains only a very annoying issue with pickle and oldstyle classes.
comment:18 Changed 6 years ago by
Milestone:  sage7.3 → sage7.4 

comment:19 Changed 6 years ago by
I'm willing to have a look at the explain_pickle.py
thing (but not right now).
comment:22 Changed 6 years ago by
Milestone:  sage7.4 → sage7.6 

comment:23 Changed 6 years ago by
Branch:  public/15994 

Commit:  50c9d97351049f66ac17ba52b8635428eef95418 
comment:24 Changed 6 years ago by
one instance of ClassType? is handled in #22918
there remains only the 2 ClassType? in explain_pickle.
comment:25 Changed 6 years ago by
Milestone:  sage7.6 → sage8.0 

comment:26 Changed 6 years ago by
Branch:  → u/jdemeyer/python_3_preparation__change_for_removed_members_of_types_module 

comment:27 Changed 6 years ago by
Authors:  Wilfried Luebbe → Jeroen Demeyer 

Commit:  → 925b5a585d6f053849ffa16a0d5329eedec015ad 
Status:  needs_work → needs_review 
This one was actually easy: you just need to pretend that isinstance(foo, types.ClassType)
is always False
on Python 3.
Note that I also did some cleanup, including adding an unrelated doctest. I hope that is acceptable.
New commits:
925b5a5  Do not require types.ClassType

comment:28 Changed 6 years ago by
Reviewers:  → Frédéric Chapoton 

Status:  needs_review → positive_review 
ok,let it be. Thanks
comment:29 Changed 6 years ago by
Branch:  u/jdemeyer/python_3_preparation__change_for_removed_members_of_types_module → 925b5a585d6f053849ffa16a0d5329eedec015ad 

Resolution:  → fixed 
Status:  positive_review → closed 
8 failed doctests in src/sage/misc/explain_pickle.py.