Opened 9 years ago

Closed 9 years ago

#16078 closed enhancement (fixed)

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

Reported by: Wilfried Luebbe 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, GitHub, GitLab) Commit: cbc5863066a3fb87a0013352117286b1c954530f
Dependencies: Stopgaps:

Status badges

Description (last modified by Wilfried Luebbe)

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 9 years ago by For batch modifications

Milestone: sage-6.2sage-6.3

comment:2 Changed 9 years ago by aapitzsch

Branch: u/aapitzsch/ticket/16078
Commit: 199db7e55872caf0d7468750e7e1f1847f768483
Status: newneeds_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 9 years ago by aapitzsch

Authors: André Apitzsch

comment:4 Changed 9 years ago by Wilfried Luebbe

Description: modified (diff)

comment:5 Changed 9 years ago by Wilfried Luebbe

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 9 years ago by aapitzsch

Branch: u/aapitzsch/ticket/16078u/aapitzsch/ticket/16078_2
Commit: 199db7e55872caf0d7468750e7e1f1847f76848399a006752fbdce476021b124cc84d8f87b347781

Moved imports to the top of each module.


New commits:

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

comment:7 Changed 9 years ago by Wilfried Luebbe

Reviewers: Wilfried Luebbe
Status: needs_reviewpositive_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 9 years ago by Volker Braun

Status: positive_reviewneeds_work

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

comment:9 Changed 9 years ago by git

Commit: 99a006752fbdce476021b124cc84d8f87b347781cbc5863066a3fb87a0013352117286b1c954530f

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

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

comment:10 Changed 9 years ago by aapitzsch

Status: needs_workneeds_review

Rebased.

comment:11 Changed 9 years ago by Wilfried Luebbe

Status: needs_reviewpositive_review

Check and tested again after merge.

comment:12 Changed 9 years ago by Volker Braun

Branch: u/aapitzsch/ticket/16078_2cbc5863066a3fb87a0013352117286b1c954530f
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.