Opened 7 years ago

Closed 3 years ago

#15994 closed enhancement (fixed)

Python 3 preparation: Change for removed members of types module

Reported by: wluebbe 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) 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 meta-ticket ticket:15980.

Attachments (1)

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

Download all attachments as: .zip

Change History (30)

Changed 7 years ago by wluebbe

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

comment:1 Changed 7 years ago by wluebbe

  • Branch set to u/wluebbe/ticket/15994
  • Commit set to 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 7 years ago by wluebbe

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 6 years ago by wluebbe

  • Status changed from new to needs_review

Status updated to allow "needs work" ...

comment:4 Changed 6 years ago by wluebbe

  • Status changed from needs_review to 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 6 years ago by ohanar

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 6 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:7 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:8 Changed 5 years ago by chapoton

  • Branch changed from u/wluebbe/ticket/15994 to public/15994
  • Commit changed from f741ed21b0019f1d6e1119bdd2038a337f7174cc to 02b3dedb16ae9f770bc9b0bb88ef6664be58f68a

comment:9 Changed 5 years ago by chapoton

  • Milestone changed from sage-6.4 to sage-7.2

comment:10 Changed 5 years ago by chapoton

  • Authors set to Wilfried Luebbe
  • Status changed from needs_work to needs_review

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

comment:11 Changed 5 years ago by git

  • Commit changed from 02b3dedb16ae9f770bc9b0bb88ef6664be58f68a to 50c9d97351049f66ac17ba52b8635428eef95418

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

50c9d97trac #15994 changing doctests in explain_pickle

comment:12 Changed 4 years ago by chapoton

  • Status changed from needs_review to needs_work

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

comment:13 Changed 4 years ago by chapoton

  • Component changed from distribution to python3

comment:14 Changed 4 years ago by chapoton

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

comment:15 Changed 4 years ago by chapoton

  • Milestone changed from sage-7.2 to sage-7.3

comment:16 Changed 4 years ago by chapoton

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

comment:17 Changed 4 years ago by chapoton

some work on that in #21230

comment:18 Changed 4 years ago by chapoton

  • Milestone changed from sage-7.3 to sage-7.4

comment:19 Changed 4 years ago by jdemeyer

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

comment:20 Changed 4 years ago by chapoton

remains one XRangeType and several ClassType

Last edited 4 years ago by chapoton (previous) (diff)

comment:21 Changed 4 years ago by chapoton

XRangeType is handled in #21867

comment:22 Changed 4 years ago by chapoton

  • Milestone changed from sage-7.4 to sage-7.6

comment:23 Changed 4 years ago by chapoton

  • Branch public/15994 deleted
  • Commit 50c9d97351049f66ac17ba52b8635428eef95418 deleted

comment:24 Changed 3 years ago by chapoton

one instance of ClassType? is handled in #22918

there remains only the 2 ClassType? in explain_pickle.

comment:25 Changed 3 years ago by chapoton

  • Milestone changed from sage-7.6 to sage-8.0

comment:26 Changed 3 years ago by jdemeyer

  • Branch set to u/jdemeyer/python_3_preparation__change_for_removed_members_of_types_module

comment:27 Changed 3 years ago by jdemeyer

  • Authors changed from Wilfried Luebbe to Jeroen Demeyer
  • Commit set to 925b5a585d6f053849ffa16a0d5329eedec015ad
  • Status changed from needs_work to 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:

925b5a5Do not require types.ClassType

comment:28 Changed 3 years ago by chapoton

  • Reviewers set to Frédéric Chapoton
  • Status changed from needs_review to positive_review

ok,let it be. Thanks

comment:29 Changed 3 years ago by vbraun

  • Branch changed from u/jdemeyer/python_3_preparation__change_for_removed_members_of_types_module to 925b5a585d6f053849ffa16a0d5329eedec015ad
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.