mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Issue #24206: Fixed __eq__ and __ne__ methods of inspect classes.
This commit is contained in:
parent
d113c967b4
commit
3018cc49e8
3 changed files with 66 additions and 38 deletions
|
@ -2206,15 +2206,13 @@ class Parameter:
|
|||
id(self), self.name)
|
||||
|
||||
def __eq__(self, other):
|
||||
return (issubclass(other.__class__, Parameter) and
|
||||
self._name == other._name and
|
||||
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)
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
|
||||
class BoundArguments:
|
||||
'''Result of `Signature.bind` call. Holds the mapping of arguments
|
||||
|
@ -2295,13 +2293,11 @@ class BoundArguments:
|
|||
return kwargs
|
||||
|
||||
def __eq__(self, other):
|
||||
return (issubclass(other.__class__, BoundArguments) and
|
||||
self.signature == other.signature and
|
||||
if not isinstance(other, BoundArguments):
|
||||
return NotImplemented
|
||||
return (self.signature == other.signature and
|
||||
self.arguments == other.arguments)
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
|
||||
class Signature:
|
||||
'''A Signature object represents the overall signature of a function.
|
||||
|
@ -2493,9 +2489,10 @@ class Signature:
|
|||
return_annotation=return_annotation)
|
||||
|
||||
def __eq__(self, other):
|
||||
if (not issubclass(type(other), Signature) or
|
||||
self.return_annotation != other.return_annotation or
|
||||
len(self.parameters) != len(other.parameters)):
|
||||
if not isinstance(other, Signature):
|
||||
return NotImplemented
|
||||
if (self.return_annotation != other.return_annotation or
|
||||
len(self.parameters) != len(other.parameters)):
|
||||
return False
|
||||
|
||||
other_positions = {param: idx
|
||||
|
@ -2522,9 +2519,6 @@ class Signature:
|
|||
|
||||
return True
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
def _bind(self, args, kwargs, *, partial=False):
|
||||
'''Private method. Don't use directly.'''
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue