Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Issue 1179044: Python: Equality and hashing for functools.partial

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 3 months ago by DUrban
Modified:
2 months, 2 weeks ago
Reviewers:
Base URL:
http://svn.python.org/view/*checkout*/python/branches/py3k/
Visibility:
Public.

Description

Python feature request: http://bugs.python.org/issue8699 On python-dev came up an idea [1] to support equality (== and !=) and hashing by functools.partial instances. Van Lindberg provided an implementation written in Python [2]. I've made a very similar implementation in C (in Modules/_functoolsmodule.c). The Python equivalent of my code is in Lib/test/test_functools.py as the PythonPartialCls class. The hashing differs a little from Van Lindberg's implementation: I'm computing the "normal form" of the dict as the sorted list of its items (not as the sorted list of the keys followed by the items). (It was easier to implement this way.) I haven't made a lot of Python programming in C, so I'm not sure I made everything in the right way (especially the reference counting). I'd appreciate every suggestion, and will try to correct my mistakes. Thanks! [1] http://mail.python.org/pipermail/python-dev/2010-May/099981.html [2] http://mail.python.org/pipermail/python-dev/2010-May/099996.html

Patch Set 1 #

Patch Set 2 : Here is a corrected version (using PyList_Sort to sort the list). #

Patch Set 3 : Corrected version, with read-only keywords dictionary. #

Patch Set 4 : Corrected version, __eq__ now compares the __dict__ of the two instances. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+198 lines, -4 lines) Patch
Lib/test/test_functools.py View 1 3 3 chunks +79 lines, -0 lines 0 comments Download
Modules/_functoolsmodule.c View 1 3 6 chunks +119 lines, -4 lines 0 comments Download

Messages

Total messages: 4
DUrban
12 years, 3 months ago (2010-05-12 15:05:17 UTC) #1
DUrban
Here is a corrected version (using PyList_Sort to sort the list).
12 years, 3 months ago (2010-05-13 07:27:42 UTC) #2
DUrban
Corrected version, with read-only keywords dictionary.
12 years, 3 months ago (2010-05-13 16:41:34 UTC) #3
DUrban
12 years, 2 months ago (2010-05-16 12:22:30 UTC) #4
Corrected version, __eq__ now compares the __dict__ of the two instances.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b