Opened 5 years ago

Closed 3 years ago

#16075 closed enhancement (fixed)

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

Reported by: wluebbe 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) Commit: 4f4db614d6fa1911b1eca63f7a4a7da062cd477f
Dependencies: Stopgaps:

Description (last modified by wluebbe)

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

  • Milestone changed from sage-6.2 to sage-6.3

comment:2 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:3 Changed 5 years ago by aapitzsch

  • Dependencies set to #17398

comment:4 Changed 4 years ago by aapitzsch

  • Dependencies changed from #17398 to #17398,#18592
  • Milestone changed from sage-6.4 to sage-6.8

comment:5 Changed 4 years ago by wluebbe

  • Description modified (diff)

comment:6 Changed 3 years ago by chapoton

  • Branch set to public/16075
  • Commit set to ed7b38b8ff391529672d7081a6999ff1d22d0eee
  • Status changed from new to needs_review

New commits:

ed7b38btrac #16075 .next into python3 format

comment:7 Changed 3 years ago by chapoton

  • Authors set to Frédéric Chapoton
  • Milestone changed from sage-6.8 to sage-7.2
  • Reviewers set to Nicolas M. Thiéry

comment:8 Changed 3 years ago by chapoton

  • Dependencies #17398,#18592 deleted

comment:9 Changed 3 years ago by git

  • Commit changed from ed7b38b8ff391529672d7081a6999ff1d22d0eee to b179553e62771458d8331f8551afe6502bdc2dbe

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 3 years ago by git

  • Commit changed from b179553e62771458d8331f8551afe6502bdc2dbe to b2eddb2ad789661b3862cd4a729f72f6dcf2f1fc

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

comment:11 Changed 3 years ago by jdemeyer

Moved minor doc improvements to #20429.

Last edited 3 years ago by nthiery (previous) (diff)

comment:12 Changed 3 years ago by git

  • Commit changed from b2eddb2ad789661b3862cd4a729f72f6dcf2f1fc to e37c92047a584df8b56a94fc4489bfcc4f7eec8b

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 3 years ago by nthiery

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

comment:14 Changed 3 years ago by git

  • Commit changed from e37c92047a584df8b56a94fc4489bfcc4f7eec8b to e68cc70a4b71667bdf3057c87a87cd01deb51dc3

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 3 years ago by nthiery

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 3 years ago by git

  • Commit changed from e68cc70a4b71667bdf3057c87a87cd01deb51dc3 to 4f4db614d6fa1911b1eca63f7a4a7da062cd477f

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

4f4db61trac 16075 two details

comment:17 Changed 3 years ago by chapoton

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

comment:18 Changed 3 years ago by nthiery

  • Status changed from needs_review to positive_review

comment:19 Changed 3 years ago by nthiery

Good to go!

comment:20 Changed 3 years ago by vbraun

  • Branch changed from public/16075 to 4f4db614d6fa1911b1eca63f7a4a7da062cd477f
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.