summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-14 22:20:01 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-14 22:20:01 (GMT)
commit692b340092c603e21f43d4116b2cc24d14fc8b04 (patch)
tree5d78d1a9a1954967287f11cff08e3b326ba285d3 /Lib/inspect.py
parent8aad7f27a4fe285bee9cfc253c374bb611230247 (diff)
downloadcpython-692b340092c603e21f43d4116b2cc24d14fc8b04.zip
cpython-692b340092c603e21f43d4116b2cc24d14fc8b04.tar.gz
cpython-692b340092c603e21f43d4116b2cc24d14fc8b04.tar.bz2
inspect: Micro-optimize __eq__ for Signature, Parameter and BoundArguments
Provide __ne__ method for consistency.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 9f4d005..ef2407c 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -2353,11 +2353,15 @@ class Parameter:
return hash((self.name, self.kind, self.annotation, self.default))
def __eq__(self, other):
- return (issubclass(other.__class__, Parameter) and
- self._name == other._name and
- self._kind == other._kind and
- self._default == other._default and
- self._annotation == other._annotation)
+ 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)
class BoundArguments:
@@ -2441,9 +2445,13 @@ class BoundArguments:
return kwargs
def __eq__(self, other):
- return (issubclass(other.__class__, BoundArguments) and
- self.signature == other.signature and
- self.arguments == other.arguments)
+ 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)
def __setstate__(self, state):
self._signature = state['_signature']
@@ -2663,8 +2671,12 @@ class Signature:
return hash((params, kwo_params, return_annotation))
def __eq__(self, other):
- return (isinstance(other, Signature) and
- self._hash_basis() == other._hash_basis())
+ return (self is other or
+ (isinstance(other, Signature) and
+ self._hash_basis() == other._hash_basis()))
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
def _bind(self, args, kwargs, *, partial=False):
"""Private method. Don't use directly."""