Last active
May 15, 2018 14:21
-
-
Save Quidge/bd6e84147a6bd2880bc3d70b3482ee66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ErrorOnDuplicateSet(object): | |
""" | |
This class behaves just like a set type collection, but will error if | |
a duplicate is added to the collection. | |
""" | |
__emulates__ = set | |
def __init__(self): | |
self.data = set() | |
@collection.appender | |
def append(self, item): | |
try: | |
assert item not in data | |
except: | |
raise | |
else: | |
self.data.add(item) | |
def remove(self, item): | |
self.data.remove(item) | |
def __iter__(self): | |
return iter(self.data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment