summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2014-04-08 15:46:50 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2014-04-08 15:46:50 (GMT)
commit67ae50ee1c723db3a0d9fb22fc182dc1854fb137 (patch)
treeabda69bbb3afcac6d6e386bd2ff2fc2f27c48336 /Lib/inspect.py
parent3f73ca23cfe4e4058689bc5a46622c68ef1b6aa6 (diff)
downloadcpython-67ae50ee1c723db3a0d9fb22fc182dc1854fb137.zip
cpython-67ae50ee1c723db3a0d9fb22fc182dc1854fb137.tar.gz
cpython-67ae50ee1c723db3a0d9fb22fc182dc1854fb137.tar.bz2
inspect: Make Signature and Parameter hashable. Issue #20334.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index eef8dc9..4ac76b1 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -2231,6 +2231,16 @@ class Parameter:
return '<{} at {:#x} "{}">'.format(self.__class__.__name__,
id(self), self)
+ def __hash__(self):
+ hash_tuple = (self.name, int(self.kind))
+
+ if self._annotation is not _empty:
+ hash_tuple += (self._annotation,)
+ if self._default is not _empty:
+ hash_tuple += (self._default,)
+
+ return hash(hash_tuple)
+
def __eq__(self, other):
return (issubclass(other.__class__, Parameter) and
self._name == other._name and
@@ -2524,6 +2534,12 @@ class Signature:
return type(self)(parameters,
return_annotation=return_annotation)
+ def __hash__(self):
+ hash_tuple = tuple(self.parameters.values())
+ if self._return_annotation is not _empty:
+ hash_tuple += (self._return_annotation,)
+ return hash(hash_tuple)
+
def __eq__(self, other):
if (not issubclass(type(other), Signature) or
self.return_annotation != other.return_annotation or