Skip to content

bpo-40651: Bugfix of the LRU implementation based on OrderedDict in the collections document #20139

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
May 18, 2020

Conversation

qudongfang
Copy link
Contributor

@qudongfang qudongfang commented May 16, 2020

bpo-40651: Bugfix of the LRU implementation based on OrderedDict in the collections module documents.

It didn't consider the calls to __setitem__ method as usage.

https://bugs.python.org/issue40651

…in the

`collections` module documents.

Signed-off-by: Dongfang Qu <[email protected]>
Copy link
Contributor

@remilapeyre remilapeyre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @qudongfang, thanks for your contribution !

@@ -1161,6 +1161,8 @@ variants of :func:`functools.lru_cache`::
return value

def __setitem__(self, key, value):
if key in self:
self.move_to_end(key)
super().__setitem__(key, value)
if len(self) > self.maxsize:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this part could be replaced by self.popitem(last=False) now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right.
It is cleaner to remove the oldest entry by self.popitem(last=False).

At the same time, It is working correctly.

Do you suggest I update it in this pull request?
Not sure about the conventions here.
Normally we are only supposed to change the code directly related to the issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, I think popitem() was added in Python3 so this block of code needed to be compatible with Python 2 until this year.

Let's wait for @rhettinger review, I can change it in another PR if he thinks it's needed.

@miss-islington
Copy link
Contributor

Thanks @qudongfang for the PR, and @rhettinger for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 18, 2020
arturoescaip pushed a commit to arturoescaip/cpython that referenced this pull request May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants