Skip to content

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

@gdlxn-ibm

Description

@gdlxn-ibm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions