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

Enhancement Request: raise exception when creating OrderedSet with duplicate entries #99

Open
gdlxn-ibm opened this issue Oct 31, 2024 · 0 comments

Comments

@gdlxn-ibm
Copy link

Currently (ordered-set 4.1.0), OrderedSet removes duplicates when both creating an OrderedSet with duplicates or when adding a duplicate element to an existing OrderedSet:

>>> s = OrderedSet([1, 1, 2, 3, 2])
>>> s
OrderedSet([1, 2, 3])
>>> s.add(1)
0
>>> s
OrderedSet([1, 2, 3])

What I'd like is an option, say FailOnDuplicate, that would raise an exception, say ValueError, when an OrderedSet is created with duplicate elements. That is, both

s = OrderedSet([1, 1, 2, 3, 2], FailOnDuplicate=True)

and

s = OrderedSet([1, 2, 3])
s.add(1)

should raise ValueError.

I realize that the Python built-in *set and frozenset have the same behavior. I think adding a similar option to set and frozenset would also be useful.

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

1 participant