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:  sage6.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: 
Description (last modified by )
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 forwardcompatible with Python 3.
New in version 2.6.
This ticket is tracked as a dependency of metaticket ticket:16052.
Change History (12)
comment:1 Changed 9 years ago by
Milestone:  sage6.2 → sage6.3 

comment:2 Changed 9 years ago by
Branch:  → u/aapitzsch/ticket/16078 

Commit:  → 199db7e55872caf0d7468750e7e1f1847f768483 
Status:  new → needs_review 
comment:3 Changed 9 years ago by
Authors:  → André Apitzsch 

comment:4 Changed 9 years ago by
Description:  modified (diff) 

comment:5 Changed 9 years ago by
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/sagetp4alllong16078.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
Branch:  u/aapitzsch/ticket/16078 → u/aapitzsch/ticket/16078_2 

Commit:  199db7e55872caf0d7468750e7e1f1847f768483 → 99a006752fbdce476021b124cc84d8f87b347781 
Moved imports to the top of each module.
New commits:
99a0067  replace builtin reduce() by functools.reduce()

comment:7 Changed 9 years ago by
Reviewers:  → Wilfried Luebbe 

Status:  needs_review → positive_review 
All tests ./sage b;./sage tp 4 all long >logs/sagetp4alllong16078_2.log
pass and the changes look good. It's a positive review for me.
comment:8 Changed 9 years ago by
Status:  positive_review → needs_work 

Conflicts, probably needs to have the next beta merged in.
comment:9 Changed 9 years ago by
Commit:  99a006752fbdce476021b124cc84d8f87b347781 → cbc5863066a3fb87a0013352117286b1c954530f 

Branch pushed to git repo; I updated commit sha1. New commits:
cbc5863  Merge remotetracking branch 'origin/develop' into py3_reduce

comment:11 Changed 9 years ago by
Status:  needs_review → positive_review 

Check and tested again after merge.
comment:12 Changed 9 years ago by
Branch:  u/aapitzsch/ticket/16078_2 → cbc5863066a3fb87a0013352117286b1c954530f 

Resolution:  → fixed 
Status:  positive_review → closed 
functools.reduce()
was made available in python 2.6 (see https://docs.python.org/2/library/functools.html#functools.reduce)New commits:
replace builtin reduce() by functools.reduce()