xloft 0.1.13__py3-none-any.whl → 0.1.15__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.
xloft/namedtuple.py
CHANGED
|
@@ -37,6 +37,12 @@ Examples:
|
|
|
37
37
|
>>> nt.update("x", 20)
|
|
38
38
|
>>> nt.x
|
|
39
39
|
20
|
|
40
|
+
>>> from xloft import NamedTuple
|
|
41
|
+
>>> nt = NamedTuple(x=10, y="Hello")
|
|
42
|
+
>>> for key, val in nt.items():
|
|
43
|
+
... print(f"Key: {key}, Value: {val}")
|
|
44
|
+
"Key: x, Value: 10"
|
|
45
|
+
"Key: y, Value: Hello"
|
|
40
46
|
>>> nt.x = 20
|
|
41
47
|
Error: AttributeDoesNotSetValue
|
|
42
48
|
>>> del nt.x
|
|
@@ -54,15 +60,11 @@ from xloft.errors import (
|
|
|
54
60
|
class NamedTuple:
|
|
55
61
|
"""This class imitates the behavior of the _named tuple_."""
|
|
56
62
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def __init__(self, **kwargs: dict[str, Any]) -> None:
|
|
60
|
-
"""Initialize the instance."""
|
|
61
|
-
vnkl = self.__class__.VAR_NAME_FOR_KEYS_LIST
|
|
62
|
-
self.__dict__[vnkl] = []
|
|
63
|
+
def __init__(self, **kwargs: dict[str, Any]) -> None: # noqa: D107
|
|
64
|
+
self.__dict__["_jWjSaNy1RbtQinsN_keys"] = []
|
|
63
65
|
for name, value in kwargs.items():
|
|
64
66
|
self.__dict__[name] = value
|
|
65
|
-
self.
|
|
67
|
+
self._jWjSaNy1RbtQinsN_keys.append(name)
|
|
66
68
|
|
|
67
69
|
def __len__(self) -> int:
|
|
68
70
|
"""Get the number of elements.
|
|
@@ -76,7 +78,7 @@ class NamedTuple:
|
|
|
76
78
|
Returns:
|
|
77
79
|
The number of elements in the tuple.
|
|
78
80
|
"""
|
|
79
|
-
return len(self.
|
|
81
|
+
return len(self._jWjSaNy1RbtQinsN_keys)
|
|
80
82
|
|
|
81
83
|
def __getattr__(self, name: str) -> Any:
|
|
82
84
|
"""Getter.
|
|
@@ -142,7 +144,7 @@ class NamedTuple:
|
|
|
142
144
|
Returns:
|
|
143
145
|
None
|
|
144
146
|
"""
|
|
145
|
-
keys: list[str] = self.
|
|
147
|
+
keys: list[str] = self._jWjSaNy1RbtQinsN_keys
|
|
146
148
|
if not key in keys:
|
|
147
149
|
err_msg = f"The key `{key}` is missing!"
|
|
148
150
|
raise KeyError(err_msg)
|
|
@@ -162,7 +164,7 @@ class NamedTuple:
|
|
|
162
164
|
Dictionary with keys and values of the tuple.
|
|
163
165
|
"""
|
|
164
166
|
attrs: dict[str, Any] = self.__dict__
|
|
165
|
-
keys: list[str] =
|
|
167
|
+
keys: list[str] = self._jWjSaNy1RbtQinsN_keys
|
|
166
168
|
return {key: attrs[key] for key in keys}
|
|
167
169
|
|
|
168
170
|
def items(self) -> list[tuple[str, Any]]:
|
|
@@ -180,7 +182,7 @@ class NamedTuple:
|
|
|
180
182
|
list[tuple[str, Any]]
|
|
181
183
|
"""
|
|
182
184
|
attrs: dict[str, Any] = self.__dict__
|
|
183
|
-
keys: list[str] =
|
|
185
|
+
keys: list[str] = self._jWjSaNy1RbtQinsN_keys
|
|
184
186
|
return [(key, attrs[key]) for key in keys]
|
|
185
187
|
|
|
186
188
|
def keys(self) -> list[str]:
|
|
@@ -195,7 +197,7 @@ class NamedTuple:
|
|
|
195
197
|
Returns:
|
|
196
198
|
List of keys.
|
|
197
199
|
"""
|
|
198
|
-
return self.
|
|
200
|
+
return self._jWjSaNy1RbtQinsN_keys
|
|
199
201
|
|
|
200
202
|
def values(self) -> list[Any]:
|
|
201
203
|
"""Get a list of values.
|
|
@@ -210,7 +212,7 @@ class NamedTuple:
|
|
|
210
212
|
List of values.
|
|
211
213
|
"""
|
|
212
214
|
attrs: dict[str, Any] = self.__dict__
|
|
213
|
-
keys: list[str] =
|
|
215
|
+
keys: list[str] = self._jWjSaNy1RbtQinsN_keys
|
|
214
216
|
return [attrs[key] for key in keys]
|
|
215
217
|
|
|
216
218
|
def has_key(self, key: str) -> bool:
|
|
@@ -228,7 +230,7 @@ class NamedTuple:
|
|
|
228
230
|
Returns:
|
|
229
231
|
True if the key exists, otherwise False.
|
|
230
232
|
"""
|
|
231
|
-
keys: list[str] = self.
|
|
233
|
+
keys: list[str] = self._jWjSaNy1RbtQinsN_keys
|
|
232
234
|
return key in keys
|
|
233
235
|
|
|
234
236
|
def has_value(self, value: Any) -> bool:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xloft
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.15
|
|
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
|
|
@@ -57,6 +57,7 @@ Description-Content-Type: text/markdown
|
|
|
57
57
|
<a href="https://github.com/kebasyaty/xloft"><img src="https://img.shields.io/github/languages/top/kebasyaty/xloft" alt="Top"></a>
|
|
58
58
|
<a href="https://github.com/kebasyaty/xloft"><img src="https://img.shields.io/github/repo-size/kebasyaty/xloft" alt="Size"></a>
|
|
59
59
|
<a href="https://github.com/kebasyaty/xloft"><img src="https://img.shields.io/github/last-commit/kebasyaty/xloft/main" alt="Last commit"></a>
|
|
60
|
+
<a href="https://github.com/kebasyaty/xloft/releases/" alt="GitHub release"><img src="https://img.shields.io/github/release/kebasyaty/xloft" alt="GitHub release"></a>
|
|
60
61
|
</p>
|
|
61
62
|
<p align="center">
|
|
62
63
|
Currently, the collection is represented by one element `NamedTuple`.
|
|
@@ -146,4 +147,4 @@ del nt.y # => raise: AttributeCannotBeDelete
|
|
|
146
147
|
|
|
147
148
|
## License
|
|
148
149
|
|
|
149
|
-
This project is licensed under the
|
|
150
|
+
This project is licensed under the [MIT](https://github.com/kebasyaty/xloft/blob/main/LICENSE "MIT").
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
xloft/__init__.py,sha256=YtzkovVqW8hLxBXxM0U7K_qqfU8XBJ1pzX6tAgTUNFw,215
|
|
2
|
+
xloft/errors.py,sha256=GYXvi2l01VUDQSs6skiOfQsKLF6tFuUhJMqNkL7BJNI,857
|
|
3
|
+
xloft/namedtuple.py,sha256=JfbEisEa00m8zLtc8TMljCZmU-a9PdoAvshE6j0jSpQ,6711
|
|
4
|
+
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
xloft-0.1.15.dist-info/METADATA,sha256=MLp8eZdlYKpEo6b-sFnob7Xt02xlzcb5VFkoRvzY-qs,6037
|
|
6
|
+
xloft-0.1.15.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
xloft-0.1.15.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
+
xloft-0.1.15.dist-info/RECORD,,
|
xloft-0.1.13.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
xloft/__init__.py,sha256=YtzkovVqW8hLxBXxM0U7K_qqfU8XBJ1pzX6tAgTUNFw,215
|
|
2
|
-
xloft/errors.py,sha256=GYXvi2l01VUDQSs6skiOfQsKLF6tFuUhJMqNkL7BJNI,857
|
|
3
|
-
xloft/namedtuple.py,sha256=t5TJ7UFX-oylUfRof8uZn-1MSuWHZk3sfDeKCEGEZFg,6758
|
|
4
|
-
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
xloft-0.1.13.dist-info/METADATA,sha256=5aLz9_lU6uhhYQBKJBhGInFAVivS2i_v8_KNy2Kb5kY,5868
|
|
6
|
-
xloft-0.1.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
-
xloft-0.1.13.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
-
xloft-0.1.13.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|