Skip to content

[OrderedDict] Implement OrderedDict.move_to_end(key, last=False) #155152

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

Open
wants to merge 22 commits into
base: gh/guilhermeleobas/164/base
Choose a base branch
from

Conversation

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Jun 4, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/155152

Note: Links to docs will display an error until the docs builds have been completed.

⏳ 13 Pending, 4 Unrelated Failures

As of commit 54feebe with merge base e619c6b (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@guilhermeleobas guilhermeleobas changed the title [dict] Implement OrderedDict.move_to_end(key, last=False) [OrderedDict] Implement OrderedDict.move_to_end(key, last=False) Jun 5, 2025
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@guilhermeleobas guilhermeleobas marked this pull request as ready for review July 10, 2025 19:30
Comment on lines 244 to 245
dict_cls = dict if user_cls is collections.defaultdict else user_cls
self.items = dict_cls({make_hashable(x): v for x, v in items.items()})
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we support arbitrary dict subclasses? If so, this causes us to execute arbitrary user code in Dynamo, which is not what we want

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My understanding is that user_cls is the base dict class (dict, defaultdict, ordereddict) and not the user class. Maybe a better name should be more appropriate here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh no. You're right. This is actually the user class. Let me change it to be the dict base class.

Comment on lines -612 to -618
val = self.items[key]
self.items.pop(key)
self.items[key] = val
Copy link
Contributor

Choose a reason for hiding this comment

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

what was wrong with the old implementation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, it's because of last=... keyword. It would be hard to implement move_to_end(key, last=False).

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants