xloft 0.1.7__py3-none-any.whl → 0.1.9__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
|
@@ -11,17 +11,18 @@ from xloft.errors import (
|
|
|
11
11
|
class NamedTuple:
|
|
12
12
|
"""Named Tuple."""
|
|
13
13
|
|
|
14
|
+
VAR_NAME_FOR_KEYS_LIST: str = "_jWjSaNy1RbtQinsN_keys"
|
|
15
|
+
|
|
14
16
|
def __init__(self, **kwargs: dict[str, Any]) -> None: # noqa: D107
|
|
15
|
-
|
|
17
|
+
vnkl = self.__class__.VAR_NAME_FOR_KEYS_LIST
|
|
18
|
+
self.__dict__[vnkl] = []
|
|
16
19
|
for name, value in kwargs.items():
|
|
17
20
|
self.__dict__[name] = value
|
|
18
|
-
self.
|
|
19
|
-
else:
|
|
20
|
-
self.__dict__["_len"] = len(self._keys)
|
|
21
|
+
self.__dict__[vnkl].append(name)
|
|
21
22
|
|
|
22
23
|
def __len__(self) -> int:
|
|
23
24
|
"""Get the number of elements."""
|
|
24
|
-
return self.
|
|
25
|
+
return len(self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST])
|
|
25
26
|
|
|
26
27
|
def __getattr__(self, name: str) -> Any:
|
|
27
28
|
"""Getter."""
|
|
@@ -47,35 +48,37 @@ class NamedTuple:
|
|
|
47
48
|
|
|
48
49
|
Attention: This is an uncharacteristic action for the type `tuple`.
|
|
49
50
|
"""
|
|
50
|
-
|
|
51
|
+
keys: list[str] = self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
|
|
52
|
+
if not key in keys:
|
|
51
53
|
err_msg = f"The key `{key}` is missing!"
|
|
52
54
|
raise KeyError(err_msg)
|
|
53
55
|
self.__dict__[key] = value
|
|
54
56
|
|
|
55
57
|
def to_dict(self) -> dict[str, Any]:
|
|
56
58
|
"""Convert to the dictionary."""
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
for key, value in self.__dict__.items()
|
|
60
|
-
if not callable(value) and not key in ["_keys", "_len"]
|
|
61
|
-
}
|
|
59
|
+
keys: list[str] = self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
|
|
60
|
+
return {key: self.__dict__[key] for key in keys}
|
|
62
61
|
|
|
63
62
|
def items(self) -> list[tuple[str, Any]]:
|
|
64
63
|
"""Return a set-like object providing a view on the NamedTuple's items."""
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
for key, value in self.__dict__.items()
|
|
68
|
-
if not callable(value) and not key in ["_keys", "_len"]
|
|
69
|
-
]
|
|
64
|
+
keys: list[str] = self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
|
|
65
|
+
return [(key, self.__dict__[key]) for key in keys]
|
|
70
66
|
|
|
71
67
|
def keys(self) -> list[str]:
|
|
72
68
|
"""Get a list of keys."""
|
|
73
|
-
return self.
|
|
69
|
+
return self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
|
|
74
70
|
|
|
75
71
|
def values(self) -> list[Any]:
|
|
76
72
|
"""Get a list of values."""
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
keys: list[str] = self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
|
|
74
|
+
return [self.__dict__[key] for key in keys]
|
|
75
|
+
|
|
76
|
+
def has_key(self, key: str) -> bool:
|
|
77
|
+
"""Returns True if the key exists, otherwise False."""
|
|
78
|
+
keys: list[str] = self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
|
|
79
|
+
return key in keys
|
|
80
|
+
|
|
81
|
+
def has_value(self, value: Any) -> bool:
|
|
82
|
+
"""Returns True if the value exists, otherwise False."""
|
|
83
|
+
values = self.values()
|
|
84
|
+
return value in values
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xloft
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.9
|
|
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
|
|
@@ -95,19 +95,18 @@ len(nt) # => 2
|
|
|
95
95
|
nt.keys() # => ["x", "y"]
|
|
96
96
|
nt.values() # => [10, "Hello"]
|
|
97
97
|
|
|
98
|
-
nt
|
|
99
|
-
nt
|
|
100
|
-
nt
|
|
101
|
-
|
|
98
|
+
nt.has_key("x") # => True
|
|
99
|
+
nt.has_key("y") # => True
|
|
100
|
+
nt.has_key("z") # => False
|
|
101
|
+
|
|
102
|
+
nt.has_value(10) # => True
|
|
103
|
+
nt.has_value("Hello") # => True
|
|
104
|
+
nt.has_value([1, 2, 3]) # => False
|
|
102
105
|
|
|
103
106
|
nt.get("x") # => 10
|
|
104
107
|
nt.get("y") # => "Hello"
|
|
105
108
|
nt.get("z") # => None
|
|
106
109
|
|
|
107
|
-
nt.x = 20 # => raise: AttributeDoesNotSetValue
|
|
108
|
-
nt.y = "Hi" # => raise: AttributeDoesNotSetValue
|
|
109
|
-
nt.z = [1, 2, 3] # => raise: AttributeDoesNotSetValue
|
|
110
|
-
|
|
111
110
|
nt.update("x", 20)
|
|
112
111
|
nt.update("y", "Hi")
|
|
113
112
|
nt.x # => 20
|
|
@@ -121,6 +120,17 @@ d["y"] # => "Hello"
|
|
|
121
120
|
for key, val in nt.items():
|
|
122
121
|
print(f"Key: {key}, Value: {val}")
|
|
123
122
|
|
|
123
|
+
nt["x"] # => raise: KeyError
|
|
124
|
+
nt["y"] # => raise: KeyError
|
|
125
|
+
nt["z"] # => raise: KeyError
|
|
126
|
+
nt["x"] = 20 # => TypeError
|
|
127
|
+
nt["y"] = "Hi" # => TypeError
|
|
128
|
+
nt["z"] = [1, 2, 3] # => TypeError
|
|
129
|
+
|
|
130
|
+
nt.x = 20 # => raise: AttributeDoesNotSetValue
|
|
131
|
+
nt.y = "Hi" # => raise: AttributeDoesNotSetValue
|
|
132
|
+
nt.z = [1, 2, 3] # => raise: AttributeDoesNotSetValue
|
|
133
|
+
|
|
124
134
|
del nt.x # => raise: AttributeCannotBeDelete
|
|
125
135
|
del nt.y # => raise: AttributeCannotBeDelete
|
|
126
136
|
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
xloft/__init__.py,sha256=yV847dKh9ROtw1fX5NHvPaHN-9cHYOfu9URQ--OVKXw,107
|
|
2
|
+
xloft/errors.py,sha256=GYXvi2l01VUDQSs6skiOfQsKLF6tFuUhJMqNkL7BJNI,857
|
|
3
|
+
xloft/namedtuple.py,sha256=rUTa_9pwZUR3ISGDtTuOJ_ifdiqClNMOD0NSRlNkdyk,2953
|
|
4
|
+
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
xloft-0.1.9.dist-info/METADATA,sha256=BkI8nk28um9CQ0l1p6vqyzefT38sJsi9_Db05HeR7TI,5677
|
|
6
|
+
xloft-0.1.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
xloft-0.1.9.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
+
xloft-0.1.9.dist-info/RECORD,,
|
xloft-0.1.7.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
xloft/__init__.py,sha256=yV847dKh9ROtw1fX5NHvPaHN-9cHYOfu9URQ--OVKXw,107
|
|
2
|
-
xloft/errors.py,sha256=GYXvi2l01VUDQSs6skiOfQsKLF6tFuUhJMqNkL7BJNI,857
|
|
3
|
-
xloft/namedtuple.py,sha256=h_1UEKR7A0WD-WUGNQBVBTGwcpRmLTyQ8czl-fVmmP4,2452
|
|
4
|
-
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
xloft-0.1.7.dist-info/METADATA,sha256=N7LrkeK_XCDXuSF5a3mIuLK3kIDum4jGDw_rQg7CNaA,5430
|
|
6
|
-
xloft-0.1.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
-
xloft-0.1.7.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
-
xloft-0.1.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|