This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Using functools.reduce() does not stop DeprecationWarning when using -3
Type: behavior Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: benjamin.peterson, brett.cannon, rhettinger
Priority: high Keywords: patch

Created on 2008-07-31 03:40 by brett.cannon, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
import_from_functools.diff benjamin.peterson, 2008-08-16 01:41
Messages (9)
msg70484 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-07-31 03:40
It turns out that functools.reduce() is simply __builtins__.reduce().
That does not stop the DeprecationWarning from using reduce() from being
raised even though the message says to use functools.reduce()!

Easiest solution is to create a wrapper for __builtin__.reduce() that
silences the warning when called.
msg70486 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2008-07-31 06:32
Can't this be handled by 2-to-3 instead of a -3 warning?
msg70526 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-07-31 17:43
On Wed, Jul 30, 2008 at 11:32 PM, Raymond Hettinger
<report@bugs.python.org> wrote:
>
> Raymond Hettinger <rhettinger@users.sourceforge.net> added the comment:
>
> Can't this be handled by 2-to-3 instead of a -3 warning?
>

Well, there is the problem of someone having a function already named
reduce() and the import. Since 2to3 can't go back and add an import,
every found use of reduce() would need to have an import inserted
somewhere. That won't work if reduce() is being used in a expression
context instead of a statement context, etc.
msg70527 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-31 18:56
Alternatively, you could move reduce to functools and have the builtin
module issue a warning and call it.
msg70533 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-07-31 23:32
On Thu, Jul 31, 2008 at 11:56 AM, Benjamin Peterson
<report@bugs.python.org> wrote:
>
> Benjamin Peterson <musiccomposition@gmail.com> added the comment:
>
> Alternatively, you could move reduce to functools and have the builtin
> module issue a warning and call it.
>

That's what 3.0 did; created _functools and that holds the original
implementation from __builtins__. But that is a lot more work. =)
msg71192 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-16 01:41
Here's a patch that actually imports reduce from functools to stop
repetition.
msg71309 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-08-18 01:52
Reviewing the patch at http://codereview.appspot.com/2968 .
msg71310 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-08-18 01:57
Reviewed in Rietveld. Only a minor change is suggested. Otherwise I
think the patch is ready to be committed, Benjamin.
msg71311 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-18 02:01
Thanks for the review! Committed in r65802.
History
Date User Action Args
2022-04-11 14:56:37adminsetgithub: 47724
2008-08-18 02:01:36benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg71311
2008-08-18 01:57:31brett.cannonsetassignee: brett.cannon -> benjamin.peterson
messages: + msg71310
2008-08-18 01:52:52brett.cannonsetmessages: + msg71309
2008-08-16 01:41:22benjamin.petersonsetpriority: release blocker -> high
keywords: + patch
messages: + msg71192
files: + import_from_functools.diff
2008-08-03 02:00:25brett.cannonsetpriority: critical -> release blocker
2008-07-31 23:33:00brett.cannonsetmessages: + msg70533
2008-07-31 18:56:12benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg70527
2008-07-31 17:43:58brett.cannonsetmessages: + msg70526
2008-07-31 06:32:37rhettingersetnosy: + rhettinger
messages: + msg70486
components: + 2to3 (2.x to 3.x conversion tool), - Library (Lib)
2008-07-31 03:40:54brett.cannoncreate