[Python-checkins] gh-102302 Micro-optimize `inspect.Parameter.__hash__` (#102303)

AlexWaygood webhook-mailer at python.org
Sat Mar 4 10:09:04 EST 2023


https://github.com/python/cpython/commit/90801e48fdd2a57c5c5a5e202ff76c3a7dc42a50
commit: 90801e48fdd2a57c5c5a5e202ff76c3a7dc42a50
branch: main
author: Gouvernathor <44340603+Gouvernathor at users.noreply.github.com>
committer: AlexWaygood <Alex.Waygood at Gmail.com>
date: 2023-03-04T15:08:57Z
summary:

gh-102302 Micro-optimize `inspect.Parameter.__hash__` (#102303)

files:
A Misc/NEWS.d/next/Library/2023-03-04-14-46-47.gh-issue-102302.-b_s6Z.rst
M Lib/inspect.py

diff --git a/Lib/inspect.py b/Lib/inspect.py
index 8bb3a375735a..166667c62cdc 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -2805,7 +2805,7 @@ def __repr__(self):
         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
index 000000000000..aaf4e62069ca
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-03-04-14-46-47.gh-issue-102302.-b_s6Z.rst
@@ -0,0 +1 @@
+Micro-optimise hashing of :class:`inspect.Parameter`, reducing the time it takes to hash an instance by around 40%.



More information about the Python-checkins mailing list