]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-102302 Micro-optimize `inspect.Parameter.__hash__` (#102303)
authorGouvernathor <44340603+Gouvernathor@users.noreply.github.com>
Sat, 4 Mar 2023 15:08:57 +0000 (16:08 +0100)
committerGitHub <noreply@github.com>
Sat, 4 Mar 2023 15:08:57 +0000 (15:08 +0000)
Lib/inspect.py
Misc/NEWS.d/next/Library/2023-03-04-14-46-47.gh-issue-102302.-b_s6Z.rst [new file with mode: 0644]

index 8bb3a375735af6ac586979d37613e2f1d8685065..166667c62cdccf84bd003d488a59647e362c5870 100644 (file)
@@ -2805,7 +2805,7 @@ class Parameter:
         return '<{} "{}">'.format(self.__class__.__name__, self)
 
     def __hash__(self):
-        return hash((self.name, self.kind, self.annotation, self.default))
+        return hash((self._name, self._kind, self._annotation, self._default))
 
     def __eq__(self, other):
         if self is other:
diff --git a/Misc/NEWS.d/next/Library/2023-03-04-14-46-47.gh-issue-102302.-b_s6Z.rst b/Misc/NEWS.d/next/Library/2023-03-04-14-46-47.gh-issue-102302.-b_s6Z.rst
new file mode 100644 (file)
index 0000000..aaf4e62
--- /dev/null
@@ -0,0 +1 @@
+Micro-optimise hashing of :class:`inspect.Parameter`, reducing the time it takes to hash an instance by around 40%.