[issue22955] Pickling of methodcaller, attrgetter, and itemgetter

Zachary Ware report at bugs.python.org
Fri Dec 12 07:36:09 CET 2014


Zachary Ware added the comment:

Serhiy: functools.partial is a somewhat less than ideal comparison.  The pure-Python version is not picklable, the Python and C versions return different things (the Python version is a function returning a function, the C version is a regular class and returns an instance).  Also, both versions make their necessary attributes public anyway, unlike methodcaller.

Raymond: Not necessarily the usual approach, no.  However, I think my reimplementations of the pure-Python itemgetter and attrgetter have a few benefits, namely:
- they're somewhat less complex and thus a bit easier to understand
- they're slightly faster
- they don't require extra pickling methods, which to me just seem like clutter when it's so simple to not need them

Note that I have no intention of reimplementing the C versions: those are much more mature than the Python versions, and would likely require pickling methods anyway.

All that said, I'm not going to fight about it; if I'm overruled, I'm overruled.

Josh: Serhiy's points about needing more tests stand; would you like to add them?  You can use your patch or mine as a base, depending on how you feel about reimplementing the pure-Python (item|attr}getter.  If you use yours, please remember to look through my comments on it.

----------

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


More information about the Python-bugs-list mailing list