[New-bugs-announce] [issue27137] functools.partial: Inconsistency between Python and C implementations
report at bugs.python.org
Fri May 27 12:39:18 EDT 2016
New submission from Emanuel Barry:
functools.partial is a class in C, but the Python implementation is a function. This doesn't matter for most use cases where you only want the end result of the call to partial.
A simple line in the REPL tells me enough (or so I thought) that I wouldn't need to check the implementation:
Oh, it's a class, which means I can subclass it to add a custom repr for my needs.
Unsurprisingly, it works. It may not be the best idea to subclass something that is meant to be final, but I'm simply overriding a single method, what could possibly go wrong? Besides one of the implementations not actually being a class.
I'm suggesting to make the Python implementation also a class, for consistency and making sure that both the C and Python implementation match, in case someone else wants to do that too.
The documentation ( https://docs.python.org/3/library/functools.html#functools.partial ) doesn't state that the Python and C implementations differ, but IMO this isn't a documentation bug.
I haven't written a patch yet, will probably be done by tomorrow.
Note: I haven't actually encountered this issue, but I suspect that it might arise if someone doesn't have access to _functools for whatever reason. And IMO, Python and C implementations of a feature should be fully equivalent (modulo implementation details à la OrderedDict.__root).
components: Library (Lib)
nosy: ebarry, ncoghlan, rhettinger
stage: needs patch
title: functools.partial: Inconsistency between Python and C implementations
versions: Python 3.6
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce