xloft 0.5.1__py3-none-any.whl → 0.5.2__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.

Potentially problematic release.


This version of xloft might be problematic. Click here for more details.

xloft/namedtuple.py CHANGED
@@ -1,55 +1,6 @@
1
1
  """This module contains the implementation of the `NamedTuple` class.
2
2
 
3
- `NamedTuple` class imitates the behavior of the _named tuple_.
4
-
5
- Examples:
6
- >>> from xloft import NamedTuple
7
- >>> nt = NamedTuple(x=10, y="Hello", _id="507c7f79bcf86cd7994f6c0e")
8
- >>> nt.x
9
- 10
10
- >>> nt.y
11
- Hello
12
- >>> nt._id
13
- 507c7f79bcf86cd7994f6c0e
14
- >>> nt.z
15
- KeyError
16
- >>> len(nt)
17
- 3
18
- >>> nt.keys()
19
- ["x", "y", "_id"]
20
- >>> nt.values()
21
- [10, "Hello", "507c7f79bcf86cd7994f6c0e"]
22
- >>> nt.has_key("x")
23
- True
24
- >>> nt.has_key("z")
25
- False
26
- >>> nt.has_value(10)
27
- True
28
- >>> nt.has_value([1, 2, 3])
29
- False
30
- >>> nt.get("x")
31
- 10
32
- >>> nt.get("z")
33
- None
34
- >>> d = nt.to_dict()
35
- >>> d["x"]
36
- 10
37
- >>> for key, val in nt.items():
38
- ... print(f"Key: {key}, Value: {val}")
39
- "Key: x, Value: 10"
40
- "Key: y, Value: Hello"
41
- "Key: _id, value: 507c7f79bcf86cd7994f6c0e"
42
- >>> nt.update("x", 20)
43
- >>> nt.x
44
- 20
45
- >>> nt.update("z", [1, 2, 3])
46
- KeyError
47
- >>> nt["z"] = [1, 2, 3]
48
- TypeError
49
- >>> nt.x = 20
50
- Error: AttributeDoesNotSetValue
51
- >>> del nt.x
52
- Error: AttributeCannotBeDelete
3
+ `NamedTuple` class imitates the behavior of the *named tuple*.
53
4
  """
54
5
 
55
6
  from __future__ import annotations
@@ -63,13 +14,13 @@ from xloft.errors import (
63
14
 
64
15
 
65
16
  class NamedTuple:
66
- """This class imitates the behavior of the _named tuple_."""
17
+ """This class imitates the behavior of the *named tuple*."""
67
18
 
68
19
  def __init__(self, **kwargs: dict[str, Any]) -> None: # noqa: D107
69
- self.__dict__["_jWjSaNy1RbtQinsN_keys"] = []
20
+ self.__dict__["_0D5rSmH9Sy2XUWb5_keys"] = []
70
21
  for name, value in kwargs.items():
71
22
  self.__dict__[name] = value
72
- self._jWjSaNy1RbtQinsN_keys.append(name)
23
+ self._0D5rSmH9Sy2XUWb5_keys.append(name)
73
24
 
74
25
  def __len__(self) -> int:
75
26
  """Get the number of elements.
@@ -83,7 +34,7 @@ class NamedTuple:
83
34
  Returns:
84
35
  The number of elements in the tuple.
85
36
  """
86
- return len(self._jWjSaNy1RbtQinsN_keys)
37
+ return len(self._0D5rSmH9Sy2XUWb5_keys)
87
38
 
88
39
  def __getattr__(self, name: str) -> Any:
89
40
  """Getter.
@@ -149,7 +100,7 @@ class NamedTuple:
149
100
  Returns:
150
101
  None
151
102
  """
152
- keys: list[str] = self._jWjSaNy1RbtQinsN_keys
103
+ keys: list[str] = self._0D5rSmH9Sy2XUWb5_keys
153
104
  if key not in keys:
154
105
  err_msg = f"The key `{key}` is missing!"
155
106
  raise KeyError(err_msg)
@@ -169,7 +120,7 @@ class NamedTuple:
169
120
  Dictionary with keys and values of the tuple.
170
121
  """
171
122
  attrs: dict[str, Any] = self.__dict__
172
- keys: list[str] = self._jWjSaNy1RbtQinsN_keys
123
+ keys: list[str] = self._0D5rSmH9Sy2XUWb5_keys
173
124
  return {key: attrs[key] for key in keys}
174
125
 
175
126
  def items(self) -> list[tuple[str, Any]]:
@@ -187,7 +138,7 @@ class NamedTuple:
187
138
  list[tuple[str, Any]]
188
139
  """
189
140
  attrs: dict[str, Any] = self.__dict__
190
- keys: list[str] = self._jWjSaNy1RbtQinsN_keys
141
+ keys: list[str] = self._0D5rSmH9Sy2XUWb5_keys
191
142
  return [(key, attrs[key]) for key in keys]
192
143
 
193
144
  def keys(self) -> list[str]:
@@ -202,7 +153,7 @@ class NamedTuple:
202
153
  Returns:
203
154
  List of keys.
204
155
  """
205
- return self._jWjSaNy1RbtQinsN_keys
156
+ return self._0D5rSmH9Sy2XUWb5_keys.copy()
206
157
 
207
158
  def values(self) -> list[Any]:
208
159
  """Get a list of values.
@@ -217,7 +168,7 @@ class NamedTuple:
217
168
  List of values.
218
169
  """
219
170
  attrs: dict[str, Any] = self.__dict__
220
- keys: list[str] = self._jWjSaNy1RbtQinsN_keys
171
+ keys: list[str] = self._0D5rSmH9Sy2XUWb5_keys
221
172
  return [attrs[key] for key in keys]
222
173
 
223
174
  def has_key(self, key: str) -> bool:
@@ -235,8 +186,7 @@ class NamedTuple:
235
186
  Returns:
236
187
  True if the key exists, otherwise False.
237
188
  """
238
- keys: list[str] = self._jWjSaNy1RbtQinsN_keys
239
- return key in keys
189
+ return key in self._0D5rSmH9Sy2XUWb5_keys
240
190
 
241
191
  def has_value(self, value: Any) -> bool:
242
192
  """Returns True if the value exists, otherwise False.
@@ -253,5 +203,4 @@ class NamedTuple:
253
203
  Returns:
254
204
  True if the value exists, otherwise False.
255
205
  """
256
- values = self.values()
257
- return value in values
206
+ return value in self.values()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xloft
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: (XLOFT) X-Library of tools
5
5
  Project-URL: Homepage, https://github.com/kebasyaty/xloft
6
6
  Project-URL: Repository, https://github.com/kebasyaty/xloft
@@ -1,9 +1,9 @@
1
1
  xloft/__init__.py,sha256=mf6z2-Tnl-CdYMa8mrI5MlTl48G0GQoYNNj2PMp8SsQ,419
2
2
  xloft/errors.py,sha256=hZcmF0QVVdvE5oM1jsXymRk_pPGgDSnUDM9wx9zJAYQ,895
3
3
  xloft/human.py,sha256=WQbVOKpOvzGot-c7f3xitbS05JUIQmj3dreGtRV6GA0,1792
4
- xloft/namedtuple.py,sha256=a_l3bZF-L2I7MGxuF2CXzAHgNai-Vyj6SY1ODwxs7TU,6856
4
+ xloft/namedtuple.py,sha256=EygsHfND0P7pw9r7Amzqi0gXsMkhpAdQVEYKDAu3rr0,5725
5
5
  xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- xloft-0.5.1.dist-info/METADATA,sha256=o24kZAXLE4z4CaUnpSlqLbl-JihkCc0eXsP4mLsZQ-M,7079
7
- xloft-0.5.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- xloft-0.5.1.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
9
- xloft-0.5.1.dist-info/RECORD,,
6
+ xloft-0.5.2.dist-info/METADATA,sha256=D5Pyg8nY1XPXiMBYMBjIWPtlZB3T-6IRKDGmeC-9PL8,7079
7
+ xloft-0.5.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ xloft-0.5.2.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
9
+ xloft-0.5.2.dist-info/RECORD,,
File without changes