summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-07-18 20:19:05 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-07-18 20:19:05 (GMT)
commit3018cc49e88721ef50c80b2d832b25dd4f0fe9d7 (patch)
treea889b4c4d7bfde2e1802643f05177ba8674a8dc8 /Lib/inspect.py
parentd113c967b4810b504d97ec97459dc85bd3a3facd (diff)
downloadcpython-3018cc49e88721ef50c80b2d832b25dd4f0fe9d7.zip
cpython-3018cc49e88721ef50c80b2d832b25dd4f0fe9d7.tar.gz
cpython-3018cc49e88721ef50c80b2d832b25dd4f0fe9d7.tar.bz2
Issue #24206: Fixed __eq__ and __ne__ methods of inspect classes.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py26
1 files changed, 10 insertions, 16 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 49e66ce..4298de6 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -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.'''