Opened 5 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:  sage6.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 )
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 5 years ago by
 Milestone changed from sage6.2 to sage6.3
comment:2 Changed 5 years ago by
 Branch set to u/aapitzsch/ticket/16078
 Commit set to 199db7e55872caf0d7468750e7e1f1847f768483
 Status changed from new to needs_review
comment:3 Changed 5 years ago by
comment:4 Changed 5 years ago by
 Description modified (diff)
comment:5 Changed 5 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 5 years ago by
 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:
99a0067  replace builtin reduce() by functools.reduce()

comment:7 Changed 5 years ago by
 Reviewers set to Wilfried Luebbe
 Status changed from needs_review to 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 5 years ago by
 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
 Commit changed from 99a006752fbdce476021b124cc84d8f87b347781 to cbc5863066a3fb87a0013352117286b1c954530f
Branch pushed to git repo; I updated commit sha1. New commits:
cbc5863  Merge remotetracking branch 'origin/develop' into py3_reduce

comment:11 Changed 5 years ago by
 Status changed from needs_review to positive_review
Check and tested again after merge.
comment:12 Changed 5 years ago by
 Branch changed from u/aapitzsch/ticket/16078_2 to cbc5863066a3fb87a0013352117286b1c954530f
 Resolution set to fixed
 Status changed from positive_review to 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()