Skip to content

gh-131525: Remove _HashedSeq wrapper from lru_cache #131922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,22 +516,6 @@ def _unwrap_partialmethod(func):

_CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"])

class _HashedSeq(list):
""" This class guarantees that hash() will be called no more than once
per element. This is important because the lru_cache() will hash
the key multiple times on a cache miss.

"""

__slots__ = 'hashvalue'

def __init__(self, tup, hash=hash):
self[:] = tup
self.hashvalue = hash(tup)

def __hash__(self):
return self.hashvalue

def _make_key(args, kwds, typed,
kwd_mark = (object(),),
fasttypes = {int, str},
Expand Down Expand Up @@ -561,7 +545,7 @@ def _make_key(args, kwds, typed,
key += tuple(type(v) for v in kwds.values())
elif len(key) == 1 and type(key[0]) in fasttypes:
return key[0]
return _HashedSeq(key)
return key

def lru_cache(maxsize=128, typed=False):
"""Least-recently-used cache decorator.
Expand Down
Loading