https://github.com/python/cpython/commit/f4de18498071f2999432e6459e54797159b6646c
commit: f4de18498071f2999432e6459e54797159b6646c
branch: main
author: Raymond Hettinger <[email protected]>
committer: rhettinger <[email protected]>
date: 2026-01-14T15:20:53-06:00
summary:
gh-143825: Micro-optimizations to _make_key. (gh-143844)
files:
M Lib/functools.py
diff --git a/Lib/functools.py b/Lib/functools.py
index 836eb680ccd4d4..075418b1605a48 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -517,7 +517,7 @@ def _unwrap_partialmethod(func):
### LRU Cache function decorator
################################################################################
-_CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"])
+_CacheInfo = namedtuple("CacheInfo", ("hits", "misses", "maxsize", "currsize"))
def _make_key(args, kwds, typed,
kwd_mark = (object(),),
@@ -539,13 +539,15 @@ def _make_key(args, kwds, typed,
# distinct call from f(y=2, x=1) which will be cached separately.
key = args
if kwds:
+ key = list(key)
key += kwd_mark
for item in kwds.items():
key += item
+ key = tuple(key)
if typed:
- key += tuple(type(v) for v in args)
+ key += tuple([type(v) for v in args])
if kwds:
- key += tuple(type(v) for v in kwds.values())
+ key += tuple([type(v) for v in kwds.values()])
elif len(key) == 1 and type(key[0]) in fasttypes:
return key[0]
return key
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]