xloft 0.1.14__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,14 +60,11 @@ from xloft.errors import (
|
|
|
54
60
|
class NamedTuple:
|
|
55
61
|
"""This class imitates the behavior of the _named tuple_."""
|
|
56
62
|
|
|
57
|
-
VAR_NAME_FOR_KEYS_LIST: str = "_jWjSaNy1RbtQinsN_keys"
|
|
58
|
-
|
|
59
63
|
def __init__(self, **kwargs: dict[str, Any]) -> None: # noqa: D107
|
|
60
|
-
|
|
61
|
-
self.__dict__[vnkl] = []
|
|
64
|
+
self.__dict__["_jWjSaNy1RbtQinsN_keys"] = []
|
|
62
65
|
for name, value in kwargs.items():
|
|
63
66
|
self.__dict__[name] = value
|
|
64
|
-
self.
|
|
67
|
+
self._jWjSaNy1RbtQinsN_keys.append(name)
|
|
65
68
|
|
|
66
69
|
def __len__(self) -> int:
|
|
67
70
|
"""Get the number of elements.
|
|
@@ -75,7 +78,7 @@ class NamedTuple:
|
|
|
75
78
|
Returns:
|
|
76
79
|
The number of elements in the tuple.
|
|
77
80
|
"""
|
|
78
|
-
return len(self.
|
|
81
|
+
return len(self._jWjSaNy1RbtQinsN_keys)
|
|
79
82
|
|
|
80
83
|
def __getattr__(self, name: str) -> Any:
|
|
81
84
|
"""Getter.
|
|
@@ -141,7 +144,7 @@ class NamedTuple:
|
|
|
141
144
|
Returns:
|
|
142
145
|
None
|
|
143
146
|
"""
|
|
144
|
-
keys: list[str] = self.
|
|
147
|
+
keys: list[str] = self._jWjSaNy1RbtQinsN_keys
|
|
145
148
|
if not key in keys:
|
|
146
149
|
err_msg = f"The key `{key}` is missing!"
|
|
147
150
|
raise KeyError(err_msg)
|
|
@@ -161,7 +164,7 @@ class NamedTuple:
|
|
|
161
164
|
Dictionary with keys and values of the tuple.
|
|
162
165
|
"""
|
|
163
166
|
attrs: dict[str, Any] = self.__dict__
|
|
164
|
-
keys: list[str] =
|
|
167
|
+
keys: list[str] = self._jWjSaNy1RbtQinsN_keys
|
|
165
168
|
return {key: attrs[key] for key in keys}
|
|
166
169
|
|
|
167
170
|
def items(self) -> list[tuple[str, Any]]:
|
|
@@ -179,7 +182,7 @@ class NamedTuple:
|
|
|
179
182
|
list[tuple[str, Any]]
|
|
180
183
|
"""
|
|
181
184
|
attrs: dict[str, Any] = self.__dict__
|
|
182
|
-
keys: list[str] =
|
|
185
|
+
keys: list[str] = self._jWjSaNy1RbtQinsN_keys
|
|
183
186
|
return [(key, attrs[key]) for key in keys]
|
|
184
187
|
|
|
185
188
|
def keys(self) -> list[str]:
|
|
@@ -194,7 +197,7 @@ class NamedTuple:
|
|
|
194
197
|
Returns:
|
|
195
198
|
List of keys.
|
|
196
199
|
"""
|
|
197
|
-
return self.
|
|
200
|
+
return self._jWjSaNy1RbtQinsN_keys
|
|
198
201
|
|
|
199
202
|
def values(self) -> list[Any]:
|
|
200
203
|
"""Get a list of values.
|
|
@@ -209,7 +212,7 @@ class NamedTuple:
|
|
|
209
212
|
List of values.
|
|
210
213
|
"""
|
|
211
214
|
attrs: dict[str, Any] = self.__dict__
|
|
212
|
-
keys: list[str] =
|
|
215
|
+
keys: list[str] = self._jWjSaNy1RbtQinsN_keys
|
|
213
216
|
return [attrs[key] for key in keys]
|
|
214
217
|
|
|
215
218
|
def has_key(self, key: str) -> bool:
|
|
@@ -227,7 +230,7 @@ class NamedTuple:
|
|
|
227
230
|
Returns:
|
|
228
231
|
True if the key exists, otherwise False.
|
|
229
232
|
"""
|
|
230
|
-
keys: list[str] = self.
|
|
233
|
+
keys: list[str] = self._jWjSaNy1RbtQinsN_keys
|
|
231
234
|
return key in keys
|
|
232
235
|
|
|
233
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.14.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=SFiiw_i5XyKADSZQovPyvXCixXssVM6NwwLXqPEjSwA,6732
|
|
4
|
-
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
xloft-0.1.14.dist-info/METADATA,sha256=RdbMIOhzcI8VMpVNjTpLzARIAVxj-rGRkGounFK3YBo,5868
|
|
6
|
-
xloft-0.1.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
-
xloft-0.1.14.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
-
xloft-0.1.14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|