Opened 6 years ago

Closed 5 years ago

#16078 closed enhancement (fixed)

Python 3 preparation: reduce() is no more a builtin function

Reported by: wluebbe Owned by:
Priority: major Milestone: sage-6.3
Component: distribution Keywords: python3
Cc: Merged in:
Authors: André Apitzsch Reviewers: Wilfried Luebbe
Report Upstream: N/A Work issues:
Branch: cbc5863 (Commits) Commit: cbc5863066a3fb87a0013352117286b1c954530f
Dependencies: Stopgaps:

Description (last modified by wluebbe)

The Py2 builtin function reduce() is available in Py3 as functools.reduce().

The tool 2to3 adds from functools import reduce.

From the |Python 2.7 documentation:
functools.reduce(function, iterable[, initializer])
This is the same function as reduce(). It is made available in this module to allow writing code more forward-compatible with Python 3. New in version 2.6.

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

Change History (12)

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 aapitzsch

  • Branch set to u/aapitzsch/ticket/16078
  • Commit set to 199db7e55872caf0d7468750e7e1f1847f768483
  • Status changed from new to needs_review

functools.reduce() was made available in python 2.6 (see https://docs.python.org/2/library/functools.html#functools.reduce)


New commits:

199db7ereplace builtin reduce() by functools.reduce()

comment:3 Changed 5 years ago by aapitzsch

  • Authors set to André Apitzsch

comment:4 Changed 5 years ago by wluebbe

  • Description modified (diff)

comment:5 Changed 5 years ago by wluebbe

I didn't realize that from functools import reduce is already possible since Python 2.6 (see the changed description).

All test passed ./sage -tp 4 --all --long >logs/sage-tp4-all-long-16078.log.

But I think it would be better (see also PEP8) to do the imports only once at the top of teach module. For 24 modules this could be generated by 2to3 - the 3 .pyx and the 1 doctest case go extra.

comment:6 Changed 5 years ago by aapitzsch

  • Branch changed from u/aapitzsch/ticket/16078 to u/aapitzsch/ticket/16078_2
  • Commit changed from 199db7e55872caf0d7468750e7e1f1847f768483 to 99a006752fbdce476021b124cc84d8f87b347781

Moved imports to the top of each module.


New commits:

99a0067replace builtin reduce() by functools.reduce()

comment:7 Changed 5 years ago by wluebbe

  • Reviewers set to Wilfried Luebbe
  • Status changed from needs_review to positive_review

All tests ./sage -b;./sage -tp 4 --all --long >logs/sage-tp4-all-long-16078_2.log pass and the changes look good. It's a positive review for me.

comment:8 Changed 5 years ago by vbraun

  • Status changed from positive_review to needs_work

Conflicts, probably needs to have the next beta merged in.

comment:9 Changed 5 years ago by git

  • Commit changed from 99a006752fbdce476021b124cc84d8f87b347781 to cbc5863066a3fb87a0013352117286b1c954530f

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

cbc5863Merge remote-tracking branch 'origin/develop' into py3_reduce

comment:10 Changed 5 years ago by aapitzsch

  • Status changed from needs_work to needs_review

Rebased.

comment:11 Changed 5 years ago by wluebbe

  • Status changed from needs_review to positive_review

Check and tested again after merge.

comment:12 Changed 5 years ago by vbraun

  • Branch changed from u/aapitzsch/ticket/16078_2 to cbc5863066a3fb87a0013352117286b1c954530f
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.