aldict 1.0.0__py3-none-any.whl → 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aldict/alias_dict.py CHANGED
@@ -8,9 +8,10 @@ class AliasDict(UserDict):
8
8
 
9
9
  def __init__(self, dict_):
10
10
  self._alias_dict = {}
11
- super().__init__(self, **dict_)
11
+ super().__init__(**dict_)
12
12
 
13
13
  def add_alias(self, key, *aliases):
14
+ """Adds one or more aliases to specified key in the dictionary"""
14
15
  if key not in self.data.keys():
15
16
  raise KeyError(key)
16
17
  for alias in aliases:
@@ -19,6 +20,7 @@ class AliasDict(UserDict):
19
20
  self._alias_dict[alias] = key
20
21
 
21
22
  def remove_alias(self, *aliases):
23
+ """Removes one or more aliases"""
22
24
  for alias in aliases:
23
25
  try:
24
26
  self._alias_dict.__delitem__(alias)
@@ -26,29 +28,43 @@ class AliasDict(UserDict):
26
28
  raise AliasError(alias) from e
27
29
 
28
30
  def clear_aliases(self):
31
+ """Removes all aliases"""
29
32
  self._alias_dict.clear()
30
33
 
31
34
  def aliases(self):
35
+ """Returns all aliases present in the dictionary"""
32
36
  return self._alias_dict.keys()
33
37
 
34
38
  def aliased_keys(self):
39
+ """Returns a dictview of all keys with their corresponding aliases"""
35
40
  result = defaultdict(list)
36
41
  for alias, key in self._alias_dict.items():
37
42
  result[key].append(alias)
38
43
  return result.items()
39
44
 
40
45
  def origin_keys(self):
46
+ """Returns all keys"""
41
47
  return self.data.keys()
42
48
 
43
49
  def keys(self):
50
+ """Returns all keys and aliases"""
44
51
  return dict(**self.data, **self._alias_dict).keys()
45
52
 
46
53
  def values(self):
54
+ """Returns all values"""
47
55
  return self.data.values()
48
56
 
49
57
  def items(self):
58
+ """Returns a dictview with all items (including alias/value tuples)"""
50
59
  return dict(**self.data, **{k: self.data[v] for k, v in self._alias_dict.items()}).items()
51
60
 
61
+ def origin_len(self):
62
+ """Returns the length of the original dictionary (without aliases)"""
63
+ return len(self.data)
64
+
65
+ def __len__(self):
66
+ return len(self.keys())
67
+
52
68
  def __missing__(self, key):
53
69
  try:
54
70
  return super().__getitem__(self._alias_dict[key])
@@ -77,9 +93,6 @@ class AliasDict(UserDict):
77
93
  for item in self.keys():
78
94
  yield item
79
95
 
80
- def __len__(self):
81
- return len(self.keys())
82
-
83
96
  def __repr__(self):
84
97
  return f"AliasDict({self.items()})"
85
98
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aldict
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Multi-key dictionary, supports adding and manipulating key-aliases pointing to shared values
5
5
  Author-email: Kaloyan Ivanov <kaloyan.ivanov88@gmail.com>
6
6
  Project-URL: repository, https://github.com/kaliv0/aldict
@@ -102,3 +102,12 @@ assert list(ad.items()) == [('x', 10), ('Xx', 10)]
102
102
  ```python
103
103
  assert list(ad.origin_keys()) == ['x', 'y']
104
104
  ```
105
+ - origin_len
106
+ <br>(get original dict <i>length</i> without aliases)
107
+ ```python
108
+ ad = AliasDict({"a": 1, "b": 2})
109
+ ad.add_alias("a", "aa")
110
+ assert list(ad.keys()) == ["a", "b", "aa"]
111
+ assert len(ad) == 3
112
+ assert ad.origin_len() == 2
113
+ ```
@@ -0,0 +1,8 @@
1
+ aldict/__init__.py,sha256=0l5cJ5LuzCZhZfx-IOk2dEsq6nJQTShr6oGmufIa9i4,153
2
+ aldict/alias_dict.py,sha256=ElEw3-HqKE7vszGnPiuZ4ZJFJnak3kettz5uKqbRh20,3273
3
+ aldict/exception.py,sha256=rFNmv9HuUOn2toPVYpVPQq6SOsl8nvwtJpGhPkK1puQ,83
4
+ aldict-1.0.1.dist-info/LICENSE,sha256=frOVyHZrx5o-fh5xC-kggT3MaLdp6yxV_YGpVXFHFSQ,1071
5
+ aldict-1.0.1.dist-info/METADATA,sha256=ZvtA-JgXEzTcJ_85CjBdr7fPCBUI3eu76Um_jV8a-yw,3381
6
+ aldict-1.0.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
7
+ aldict-1.0.1.dist-info/top_level.txt,sha256=pXwIKxRsbW2_Lh1HM-4cG2xE44RBzMz07GaY2EONV5M,7
8
+ aldict-1.0.1.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- aldict/__init__.py,sha256=0l5cJ5LuzCZhZfx-IOk2dEsq6nJQTShr6oGmufIa9i4,153
2
- aldict/alias_dict.py,sha256=OItYhSFBKCrmjHlL_2yPuwtD7G68oQ3fW31UX_e-q54,2670
3
- aldict/exception.py,sha256=rFNmv9HuUOn2toPVYpVPQq6SOsl8nvwtJpGhPkK1puQ,83
4
- aldict-1.0.0.dist-info/LICENSE,sha256=frOVyHZrx5o-fh5xC-kggT3MaLdp6yxV_YGpVXFHFSQ,1071
5
- aldict-1.0.0.dist-info/METADATA,sha256=SXO3ueZ7ut4vfdbCJpWa2pvfppvakjYX5DbIUlo45j8,3152
6
- aldict-1.0.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
7
- aldict-1.0.0.dist-info/top_level.txt,sha256=pXwIKxRsbW2_Lh1HM-4cG2xE44RBzMz07GaY2EONV5M,7
8
- aldict-1.0.0.dist-info/RECORD,,
File without changes