Opened 8 years ago

Closed 6 years ago

#16075 closed enhancement (fixed)

Python 3 preparation: Handle the changes to "next()"

Reported by: Wilfried Luebbe Owned by:
Priority: major Milestone: sage-7.2
Component: distribution Keywords: python3
Cc: Merged in:
Authors: Frédéric Chapoton Reviewers: Nicolas M. Thiéry
Report Upstream: N/A Work issues:
Branch: 4f4db61 (Commits, GitHub, GitLab) Commit: 4f4db614d6fa1911b1eca63f7a4a7da062cd477f
Dependencies: Stopgaps:

Status badges

Description (last modified by Wilfried Luebbe)

To advance some iterator it in Py2 often the iterator method is called directly it.next(). But since Python 2.6 there is the builtin function next() which is compatible between Py2 and Py3: in Py2 it calls the iterator method next() while in Py3 it calls the special method __next__().

This conversion from it.next() to next(it) can be performed safely in stage 1 (see also the remarks about lib2to3.fixes.fix_next in http://python-future.org/automatic_conversion.html#stage-1-safe-fixes).

Remarks: The changes to the iterator protocol from Py2 next() to Py3 __next__() are subject of #18802 in stage 2.

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

Change History (20)

comment:1 Changed 8 years ago by For batch modifications

Milestone: sage-6.2sage-6.3

comment:2 Changed 8 years ago by For batch modifications

Milestone: sage-6.3sage-6.4

comment:3 Changed 8 years ago by aapitzsch

Dependencies: #17398

comment:4 Changed 7 years ago by aapitzsch

Dependencies: #17398#17398,#18592
Milestone: sage-6.4sage-6.8

comment:5 Changed 7 years ago by Wilfried Luebbe

Description: modified (diff)

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

Branch: public/16075
Commit: ed7b38b8ff391529672d7081a6999ff1d22d0eee
Status: newneeds_review

New commits:

ed7b38btrac #16075 .next into python3 format

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

Authors: Frédéric Chapoton
Milestone: sage-6.8sage-7.2
Reviewers: Nicolas M. Thiéry

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

Dependencies: #17398,#18592

comment:9 Changed 6 years ago by git

Commit: ed7b38b8ff391529672d7081a6999ff1d22d0eeeb179553e62771458d8331f8551afe6502bdc2dbe

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

b2eddb216075: revert 5e09bde1; the next method here is not meant to implement the iterator protocol
b17955316075: while we are at it, some minor doc improvements

comment:10 Changed 6 years ago by git

Commit: b179553e62771458d8331f8551afe6502bdc2dbeb2eddb2ad789661b3862cd4a729f72f6dcf2f1fc

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

comment:11 Changed 6 years ago by Jeroen Demeyer

Moved minor doc improvements to #20429.

Last edited 6 years ago by Nicolas M. Thiéry (previous) (diff)

comment:12 Changed 6 years ago by git

Commit: b2eddb2ad789661b3862cd4a729f72f6dcf2f1fce37c92047a584df8b56a94fc4489bfcc4f7eec8b

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

b17955316075: while we are at it, some minor doc improvements
4227bf416075: method renaming + comment to highlight that this is not following Python's protocol iterator, and thus not subject to Py2 -> Py3 incompatibility
df0d54f16075: review
e37c92016075: xxx.next() -> next(xxx) in boost_graph for Python3 compatibility

comment:13 Changed 6 years ago by Nicolas M. Thiéry

Ah shoot, I still need to remove that commit from my branch. On it's way ...

comment:14 Changed 6 years ago by git

Commit: e37c92047a584df8b56a94fc4489bfcc4f7eec8be68cc70a4b71667bdf3057c87a87cd01deb51dc3

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

bc6a1e316075: xxx.next() -> next(xxx) in boost_graph for Python3 compatibility
45f6fb516075: review
e68cc7016075: method renaming + comment to highlight that this is not following Python's protocol iterator, and thus not subject to Py2 -> Py3 incompatibility

comment:15 Changed 6 years ago by Nicolas M. Thiéry

Ok, done. Now all the Python level calls to .next() on an actual iterator have been replaced by calls to next(...).

I have left most Cython files alone (or more precisely unrolled my changes after seeing that they were breaking stuff). The iterator protocol there already uses .__next__, so probably there is nothing to be changed. I could not find a good ref on the web about Cython + the iterator protocal + migration to Python 3 though.

I believe this is good to go. Frédéric, please proofread my changes!

comment:16 Changed 6 years ago by git

Commit: e68cc70a4b71667bdf3057c87a87cd01deb51dc34f4db614d6fa1911b1eca63f7a4a7da062cd477f

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

4f4db61trac 16075 two details

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

ok for me. If you agree with my last commit, you can set a positive review.

comment:18 Changed 6 years ago by Nicolas M. Thiéry

Status: needs_reviewpositive_review

comment:19 Changed 6 years ago by Nicolas M. Thiéry

Good to go!

comment:20 Changed 6 years ago by Volker Braun

Branch: public/160754f4db614d6fa1911b1eca63f7a4a7da062cd477f
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.