MCPcopy
hub / github.com/django/django / OrderedSet

Class OrderedSet

django/utils/datastructures.py:5–42  ·  view source on GitHub ↗

A set which keeps the ordering of the inserted items.

Source from the content-addressed store, hash-verified

3
4
5class OrderedSet:
6 """
7 A set which keeps the ordering of the inserted items.
8 """
9
10 def __init__(self, iterable=None):
11 self.dict = dict.fromkeys(iterable or ())
12
13 def add(self, item):
14 self.dict[item] = None
15
16 def remove(self, item):
17 del self.dict[item]
18
19 def discard(self, item):
20 try:
21 self.remove(item)
22 except KeyError:
23 pass
24
25 def __iter__(self):
26 return iter(self.dict)
27
28 def __reversed__(self):
29 return reversed(self.dict)
30
31 def __contains__(self, item):
32 return item in self.dict
33
34 def __bool__(self):
35 return bool(self.dict)
36
37 def __len__(self):
38 return len(self.dict)
39
40 def __repr__(self):
41 data = repr(list(self.dict)) if self.dict else ""
42 return f"{self.__class__.__qualname__}({data})"
43
44
45class MultiValueDictKeyError(KeyError):

Callers 15

pythonMethod · 0.90
validateMethod · 0.90
get_constraintsMethod · 0.90
_generate_planMethod · 0.90
all_parentsMethod · 0.90
process_rhsMethod · 0.90
test_removeMethod · 0.90
test_discardMethod · 0.90
test_reversedMethod · 0.90
test_containsMethod · 0.90

Calls

no outgoing calls

Tested by 8

test_removeMethod · 0.72
test_discardMethod · 0.72
test_reversedMethod · 0.72
test_containsMethod · 0.72
test_boolMethod · 0.72
test_lenMethod · 0.72
test_reprMethod · 0.72