Opened 8 years ago

Last modified 4 years ago

#16085 closed defect

Python 3 preparation: Py2 vs. Py3 value of type() in doctests — at Version 18

Reported by: wluebbe Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: python3 Keywords: python3
Cc: embray Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by chapoton)

In Py2 we have

Python 2.7.5+ (default, Feb 27 2014, 19:37:08) 
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> b = True
>>> type(b)
<type 'bool'>

while in Py3

Python 3.3.2+ (default, Feb 28 2014, 00:52:16) 
[GCC 4.8.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> b = True
>>> type(b)
<class 'bool'>

The result may be unified with isinstance(). Py2

>>> isinstance(b, bool)
True

and Py3

>>> isinstance(b, bool)
True

A simpler way is to use "..." instead of "type" or "class". This can be automated using something like

grep -rl "<type 'list" src/sage/ | xargs sed -i "s/<type 'list/<... 'list/g"

About 161 py module are effected.

This ticket is tracked as a dependency of meta-ticket ticket:16052.

Using:

egrep -R --no-filename -o "<type '[a-z]*'>" src/sage | sort | uniq -c | sort -rn

to find what needs to be done in src/sage:

  • 73 <type 'int'> #22233
  • 65 <type 'tuple'> #22292
  • 43 <type 'object'>
  • 35 <type 'float'> #22292
  • 32 <type 'str'> #22060
  • 22 <type 'dict'> #22292
  • 18 <type 'generator'> #22292
  • 9 <type 'function'> #22292
  • 9 <type 'bool'> #22233
  • 8 <type 'long'> !!! This one does no longer exists in Py3 !!!
  • 5 <type 'instance'> #23073
  • 5 <type 'complex'> #22233
  • 4 <type 'frozenset'> #22233
  • 3 <type 'type'> #22233
  • 1 <type 'set'> #22233

and in src/doc (see #22114):

Change History (18)

comment:1 Changed 8 years ago by wluebbe

  • Description modified (diff)

comment:2 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:3 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:4 Changed 6 years ago by jdemeyer

  • Component changed from distribution to python3

comment:5 Changed 6 years ago by chapoton

see #21904 for list and #22060 for str

comment:6 Changed 6 years ago by chapoton

  • Milestone changed from sage-6.4 to sage-7.5

comment:7 Changed 6 years ago by chapoton

  • Description modified (diff)
  • Type changed from enhancement to defect

comment:8 Changed 6 years ago by chapoton

  • Description modified (diff)

comment:9 Changed 6 years ago by chapoton

  • Description modified (diff)

comment:10 Changed 6 years ago by chapoton

  • Description modified (diff)

comment:11 Changed 6 years ago by chapoton

  • Description modified (diff)

comment:12 Changed 6 years ago by chapoton

  • Milestone changed from sage-7.5 to sage-7.6

comment:13 Changed 6 years ago by chapoton

  • Description modified (diff)

comment:14 Changed 6 years ago by chapoton

  • Description modified (diff)

comment:15 Changed 6 years ago by chapoton

  • Description modified (diff)

comment:16 Changed 6 years ago by chapoton

  • Description modified (diff)

another step in #22292

comment:17 Changed 5 years ago by chapoton

  • Milestone changed from sage-7.6 to sage-8.0

comment:18 Changed 5 years ago by chapoton

  • Description modified (diff)

next step in #23073

Note: See TracTickets for help on using tickets.