A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-May/099981.html below:

[Python-Dev] Possible patch for functools partial

[Python-Dev] Possible patch for functools partial - Interested? [Python-Dev] Possible patch for functools partial - Interested?VanL van.lindberg at gmail.com
Fri May 7 16:37:33 CEST 2010
Howdy all -

I have an app where I am using functools.partial to bundle up jobs to
do, where a job is defined as a callable + args. In one case, I wanted
to keep track of whether I had previously seen a job, so I started
putting them into a set... only to find out that partials never test
equal to each other:

>>> import operator
>>> from functools import partial
>>> p1 = partial(operator.add)
>>> p2 = partial(operator.add)
>>> p1 == p2
False
>>> seen = set();seen.add(p1)
>>> p2 in seen
False

I created a subclass of functools.partial that provides appropriate
__eq__ and __hash__ methods, so that this works as expected. I called
the subclass a Job:
>>> j1 = Job(operator.add)
>>> j2 = Job(operator.add)
>>> j1 == j2
True
>>> seen = set();seen.add(j1)
>>> j2 in seen
True
>>> j1 is j2
False

While I was at it, I also added a nice repr. Would this group be
interested in a patch, or is this not interesting?

Thanks,

Van

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4