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: sage-8.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:

Status badges

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 meta-ticket ticket:15980.

Attachments (1)

failed-doctests-15994.log (15.9 KB) - added by Wilfried Luebbe 9 years ago.
8 failed doctests in src/sage/misc/explain_pickle.py.

Download all attachments as: .zip

Change History (30)

Changed 9 years ago by Wilfried Luebbe

Attachment: failed-doctests-15994.log added

8 failed doctests in src/sage/misc/explain_pickle.py.

comment:1 Changed 9 years ago by Wilfried Luebbe

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:

f741ed2changes generated by 2to3 tool (types) for Python 3

comment:2 Changed 9 years ago by Wilfried Luebbe

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 Wilfried Luebbe

Status: newneeds_review

Status updated to allow "needs work" ...

comment:4 Changed 9 years ago by Wilfried Luebbe

Status: needs_reviewneeds_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 R. Andrew Ohana

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 For batch modifications

Milestone: sage-6.2sage-6.3

comment:7 Changed 8 years ago by For batch modifications

Milestone: sage-6.3sage-6.4

comment:8 Changed 7 years ago by Frédéric Chapoton

Branch: u/wluebbe/ticket/15994public/15994
Commit: f741ed21b0019f1d6e1119bdd2038a337f7174cc02b3dedb16ae9f770bc9b0bb88ef6664be58f68a

comment:9 Changed 7 years ago by Frédéric Chapoton

Milestone: sage-6.4sage-7.2

comment:10 Changed 7 years ago by Frédéric Chapoton

Authors: Wilfried Luebbe
Status: needs_workneeds_review

I am temporarily putting this to needs review to see what are the errors now.

comment:11 Changed 7 years ago by git

Commit: 02b3dedb16ae9f770bc9b0bb88ef6664be58f68a50c9d97351049f66ac17ba52b8635428eef95418

Branch pushed to git repo; I updated commit sha1. New commits:

50c9d97trac #15994 changing doctests in explain_pickle

comment:12 Changed 7 years ago by Frédéric Chapoton

Status: needs_reviewneeds_work

If somebody with expertise in pickles could have a look, that would be great.

comment:13 Changed 7 years ago by Frédéric Chapoton

Component: distributionpython3

comment:14 Changed 7 years ago by Frédéric Chapoton

Let us split the "more easy" part of that in #20962.

comment:15 Changed 7 years ago by Frédéric Chapoton

Milestone: sage-7.2sage-7.3

comment:16 Changed 7 years ago by Frédéric Chapoton

There remains only a very annoying issue with pickle and old-style classes.

comment:17 Changed 6 years ago by Frédéric Chapoton

some work on that in #21230

comment:18 Changed 6 years ago by Frédéric Chapoton

Milestone: sage-7.3sage-7.4

comment:19 Changed 6 years ago by Jeroen Demeyer

I'm willing to have a look at the explain_pickle.py thing (but not right now).

comment:20 Changed 6 years ago by Frédéric Chapoton

remains one XRangeType and several ClassType

Last edited 6 years ago by Frédéric Chapoton (previous) (diff)

comment:21 Changed 6 years ago by Frédéric Chapoton

XRangeType is handled in #21867

comment:22 Changed 6 years ago by Frédéric Chapoton

Milestone: sage-7.4sage-7.6

comment:23 Changed 6 years ago by Frédéric Chapoton

Branch: public/15994
Commit: 50c9d97351049f66ac17ba52b8635428eef95418

comment:24 Changed 6 years ago by Frédéric Chapoton

one instance of ClassType? is handled in #22918

there remains only the 2 ClassType? in explain_pickle.

comment:25 Changed 6 years ago by Frédéric Chapoton

Milestone: sage-7.6sage-8.0

comment:26 Changed 6 years ago by Jeroen Demeyer

Branch: u/jdemeyer/python_3_preparation__change_for_removed_members_of_types_module

comment:27 Changed 6 years ago by Jeroen Demeyer

Authors: Wilfried LuebbeJeroen Demeyer
Commit: 925b5a585d6f053849ffa16a0d5329eedec015ad
Status: needs_workneeds_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:

925b5a5Do not require types.ClassType

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

Reviewers: Frédéric Chapoton
Status: needs_reviewpositive_review

ok,let it be. Thanks

comment:29 Changed 6 years ago by Volker Braun

Branch: u/jdemeyer/python_3_preparation__change_for_removed_members_of_types_module925b5a585d6f053849ffa16a0d5329eedec015ad
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.