[issue20334] make inspect Signature hashable
Yury Selivanov added the comment: Antonie, I'm attaching a patch (issue20334-2.01.patch) to this issue which should fix the problem. Please review. -- Added file: http://bugs.python.org/file36607/issue20334-2.01.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20334] make inspect Signature hashable
Antony Lee added the comment: While your patch works, I think it is a good opportunity to simplify the implementation of Signature.__eq__, which is *much* more complicated than what it should be. Please comment on the attached patch, which uses the helper method approach I suggested. -- Added file: http://bugs.python.org/file36610/signature-hash-and-equality.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20334] make inspect Signature hashable
Roundup Robot added the comment: New changeset 3b974b61e74d by Yury Selivanov in branch 'default': inspect.Signature: Fix discrepancy between __eq__ and __hash__. http://hg.python.org/cpython/rev/3b974b61e74d -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20334] make inspect Signature hashable
Yury Selivanov added the comment: Antony, I've tweaked the patch a bit and it's now in default branch. Thank you! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20334] make inspect Signature hashable
Antony Lee added the comment: The hash function of the Signature class is actually incompatible with the definition of Signature equality, which doesn't consider the order of keyword-only arguments: from inspect import signature s1 = signature(lambda *, x, y: None); s2 = signature(lambda *, y, x: None) s1 == s2 True hash(s1) == hash(s2) False Actually the implementation of Signature.__eq__ seems way too complicated; I would suggest making a helper method returning (return_annotation, tuple(non-kw-only-params), frozenset(kw-only-params)) so that __eq__ can compare these values while __hash__ can hash that tuple. -- nosy: +Antony.Lee ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20334] make inspect Signature hashable
Yury Selivanov added the comment: Thanks, Antony, this is a good catch. Your suggestion seems like a good idea. I'll look into this more closely soon. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20334] make inspect Signature hashable
Antony Lee added the comment: Actually, that specific solution (using a helper method) will fail because there may be unhashable params (due to unhashable default values or annotations) among the keyword-only arguments, so it may not be possible to build a frozenset (rather, one should compare the {param.name: param if param.kind == KEYWORD_ONLY} dict). The frozenset approach still works for computing the hash as this requires all params to be hashable anyways. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20334] make inspect Signature hashable
Roundup Robot added the comment: New changeset 932d69ef0c63 by Yury Selivanov in branch 'default': inspect: Make Signature and Parameter hashable. Issue #20334. http://hg.python.org/cpython/rev/932d69ef0c63 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20334] make inspect Signature hashable
Changes by Yury Selivanov yselivanov...@gmail.com: -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20334] make inspect Signature hashable
Yury Selivanov added the comment: If nobody has any objections on this, I'm going to commit this in 3.5 soon. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20334] make inspect Signature hashable
New submission from Yury Selivanov: inspect.Signature and inspect.Parameter are immutable structures, and it makes sense to make them hashable too. Patch is attached. -- components: Library (Lib) files: hashable_signature_01.patch keywords: patch messages: 208671 nosy: brett.cannon, larry, ncoghlan, yselivanov priority: normal severity: normal status: open title: make inspect Signature hashable type: enhancement versions: Python 3.4 Added file: http://bugs.python.org/file33595/hashable_signature_01.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20334] make inspect Signature hashable
Yury Selivanov added the comment: Fair enough. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20334] make inspect Signature hashable
Brett Cannon added the comment: This is a new feature so it can't go into Python 3.4. -- versions: +Python 3.5 -Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20334 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com