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

Support an option to create immutable set #35

Closed
rominf opened this issue Sep 7, 2018 · 4 comments
Closed

Support an option to create immutable set #35

rominf opened this issue Sep 7, 2018 · 4 comments

Comments

@rominf
Copy link
Contributor

rominf commented Sep 7, 2018

I need to pass ordered set as function default argument, therefore, I need an immutable set. Please provide a way to create an immutable set.

@rspeer
Copy link
Owner

rspeer commented Sep 14, 2018

I'm worried about scope creep.

An immutable version of OrderedSet would clearly be useful in a few cases, but maybe it should just be a different package. There's a lot of methods of OrderedSet that it wouldn't need.

@rominf
Copy link
Contributor Author

rominf commented Mar 6, 2019

But that means that lot's of code would be duplicated. Isn't possible to create a base class to implement all common functionality and create two subclasses?

@rspeer
Copy link
Owner

rspeer commented Mar 6, 2019

I'm really not interested in writing extra code for this use case. When you need a small immutable sequence that you can use as a default argument, a tuple should do just fine.

@rspeer rspeer closed this as completed Mar 6, 2019
@Eric-Arellano
Copy link
Contributor

Hello, rather than this being a flag on the original OrderedSet, I'd love for there to be a new FrozenOrderedSet (like frozenset but ordered).

I am happy to put up a PR for this, including comprehensive tests and type hints, given your blessing. (It's okay if you don't want to commit to it at this point - if you'd like to see the PR first before accepting the overall idea, let me know and I'd be happy to do so.)

Why do I care about this? I'm one of the maintainers of Pex and Pants. For the build tool Pants, our caching model depends on stable iteration and immutability. OrderedSet provides is this first property, and we're hoping to add FrozenOrderedSet to have both properties. We thought about inlining it, but believe FrozenOrderedSet would be helpful to others.

(Possible further context: Python is considering PEP 603 to add a builtin frozenmap: https://www.python.org/dev/peps/pep-0603/)

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

No branches or pull requests

3 participants