summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
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