Skip to content
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

Replace ordered_set with dict #4574

Merged
merged 3 commits into from
Aug 19, 2024
Merged

Replace ordered_set with dict #4574

merged 3 commits into from
Aug 19, 2024

Conversation

abravalheri
Copy link
Contributor

@abravalheri abravalheri commented Aug 16, 2024

Summary of changes

This is a follow up of the discussion on #4457 (review).

Since Python 3.7, dict preserve insertion order.
This means that dict is a capable implementation of an ordered set,
despite the method names not lining up completely.

We can effectively use dict to obtain the same functionality that would be implemented by ordered_set and therefore we can remove the extra dependency.

Closes

Pull Request Checklist


Optionally, we could have something like

# setuptools/_ordered_set.py

from collections.abc import MutableSet

class ordered_set(dict, MutableSet):
    add = dict.setdefault

    def discard(self, item):
        self.pop(item, None)

But that would be mostly cosmetic, since we can simply use the dict methods directly and obtain the same effects...

Since Python 3.7, ``dict`` preserve insertion order.
This means that ``dict`` is a capable implementation of an ordered set,
despite the method names not lining up completely.
@abravalheri abravalheri changed the title Ordered set Replace ordered_set with dict Aug 16, 2024
@abravalheri abravalheri marked this pull request as ready for review August 16, 2024 15:08
@Avasam
Copy link
Contributor

Avasam commented Aug 17, 2024

Searching for "ordered" in python files, there's a few bits of logic that still assume dicts are unordered. It's getting late here, but I could open a PR in parallel of yours with all those I found.

@@ -188,7 +188,7 @@ def test_read_metadata(name, attrs):
('requires', dist_class.get_requires),
Copy link
Contributor

Choose a reason for hiding this comment

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

Line 313 still contains a reference to "ordered-set==3.1.1" (it's in an example, but may as well remove it)

Copy link
Member

Choose a reason for hiding this comment

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

I'm +0.

Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM.

@jaraco jaraco merged commit 8afe0c3 into pypa:main Aug 19, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants