diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-07-18 20:20:50 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-07-18 20:20:50 (GMT) |
commit | 2489bd5d4e45b2a1d90f9336bf528ab1bba2d796 (patch) | |
tree | 807b68918b59cbadf99e71afa796ba6fda4c02cf /Lib/inspect.py | |
parent | f12e3e2b695d56ca6ac8a4fe0a74016dacbab478 (diff) | |
parent | 3018cc49e88721ef50c80b2d832b25dd4f0fe9d7 (diff) | |
download | cpython-2489bd5d4e45b2a1d90f9336bf528ab1bba2d796.zip cpython-2489bd5d4e45b2a1d90f9336bf528ab1bba2d796.tar.gz cpython-2489bd5d4e45b2a1d90f9336bf528ab1bba2d796.tar.bz2 |
Issue #24206: Fixed __eq__ and __ne__ methods of inspect classes.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 45679cf..42f24cd 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -2488,15 +2488,14 @@ class Parameter: return hash((self.name, self.kind, self.annotation, self.default)) def __eq__(self, other): - return (self is other or - (issubclass(other.__class__, Parameter) and - self._name == other._name and - self._kind == other._kind and - self._default == other._default and - self._annotation == other._annotation)) - - def __ne__(self, other): - return not self.__eq__(other) + if self is other: + return True + if not isinstance(other, Parameter): + return NotImplemented + return (self._name == other._name and + self._kind == other._kind and + self._default == other._default and + self._annotation == other._annotation) class BoundArguments: @@ -2610,13 +2609,12 @@ class BoundArguments: self.arguments = OrderedDict(new_arguments) def __eq__(self, other): - return (self is other or - (issubclass(other.__class__, BoundArguments) and - self.signature == other.signature and - self.arguments == other.arguments)) - - def __ne__(self, other): - return not self.__eq__(other) + if self is other: + return True + if not isinstance(other, BoundArguments): + return NotImplemented + return (self.signature == other.signature and + self.arguments == other.arguments) def __setstate__(self, state): self._signature = state['_signature'] @@ -2775,12 +2773,11 @@ class Signature: return hash((params, kwo_params, return_annotation)) def __eq__(self, other): - return (self is other or - (isinstance(other, Signature) and - self._hash_basis() == other._hash_basis())) - - def __ne__(self, other): - return not self.__eq__(other) + if self is other: + return True + if not isinstance(other, Signature): + return NotImplemented + return self._hash_basis() == other._hash_basis() def _bind(self, args, kwargs, *, partial=False): """Private method. Don't use directly.""" |