Issue #24206: Fixed __eq__ and __ne__ methods of inspect classes.

This commit is contained in:
Serhiy Storchaka 2015-07-18 23:20:50 +03:00
commit 2489bd5d4e
3 changed files with 76 additions and 45 deletions

View file

@ -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."""