[issue27137] functools.partial: Inconsistency between Python and C implementations

Emanuel Barry report at bugs.python.org
Fri May 27 23:19:54 EDT 2016


Emanuel Barry added the comment:

Attached patch turns the Python implementation of functools.partial into a class. The implementation is as close to the C version as possible, except __repr__ where I went for a different, more Pythonic approach (output is identical).

I haven't yet added tests for this, and I had to fix something (because some errors occur if _functools is not present and that's the only way I know to make the tests run against the Python implementation). One test fails with the patch (and sys.modules["_functools"] = None):

...........................................................E....................
....................................................................
======================================================================
ERROR: test_pickle (test.test_functools.TestPartialC)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "E:\GitHub\cpython\lib\test\test_functools.py", line 224, in test_pickle
    f_copy = pickle.loads(pickle.dumps(f, proto))
_pickle.PicklingError: Can't pickle <class 'functools.partial'>: it's not the sa
me object as functools.partial

----------------------------------------------------------------------
Ran 148 tests in 0.216s

FAILED (errors=1)

I'll try to see what kind of tests I can add to this to reliably test both 'partial' implementations. I'll also see what I can do about that one failing test. Oddly enough, there seems to be a test for subclassing '_functools.partial', which I might extend.

Raymond, what do you think?

----------
keywords: +patch
stage: needs patch -> patch review
Added file: http://bugs.python.org/file43035/functools_partial_1.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27137>
_______________________________________


More information about the Python-bugs-list mailing list