xloft 0.1.9__py3-none-any.whl → 0.1.10__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/__init__.py +6 -1
- xloft/namedtuple.py +184 -18
- {xloft-0.1.9.dist-info → xloft-0.1.10.dist-info}/METADATA +7 -7
- xloft-0.1.10.dist-info/RECORD +8 -0
- xloft-0.1.9.dist-info/RECORD +0 -8
- {xloft-0.1.9.dist-info → xloft-0.1.10.dist-info}/WHEEL +0 -0
- {xloft-0.1.9.dist-info → xloft-0.1.10.dist-info}/licenses/LICENSE +0 -0
xloft/__init__.py
CHANGED
xloft/namedtuple.py
CHANGED
|
@@ -1,4 +1,48 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""NamedTuple.
|
|
2
|
+
|
|
3
|
+
This module contains the implementation of the `NamedTuple` class.
|
|
4
|
+
`NamedTuple` class imitates the behavior of the _named tuple_.
|
|
5
|
+
|
|
6
|
+
Examples:
|
|
7
|
+
>>> from xloft import NamedTuple
|
|
8
|
+
>>> nt = NamedTuple(x=10, y="Hello")
|
|
9
|
+
>>> nt.x
|
|
10
|
+
10
|
|
11
|
+
>>> nt.z
|
|
12
|
+
KeyError
|
|
13
|
+
>>> len(nt)
|
|
14
|
+
2
|
|
15
|
+
>>> nt.keys()
|
|
16
|
+
["x", "y"]
|
|
17
|
+
>>> nt.values()
|
|
18
|
+
[10, "Hello"]
|
|
19
|
+
>>> nt.has_key("x")
|
|
20
|
+
True
|
|
21
|
+
>>> nt.has_key("z")
|
|
22
|
+
False
|
|
23
|
+
>>> nt.has_value(10)
|
|
24
|
+
True
|
|
25
|
+
>>> nt.has_value([1, 2, 3])
|
|
26
|
+
False
|
|
27
|
+
>>> nt.get("x")
|
|
28
|
+
10
|
|
29
|
+
>>> nt.get("z")
|
|
30
|
+
None
|
|
31
|
+
>>> nt.update("z", [1, 2, 3])
|
|
32
|
+
KeyError
|
|
33
|
+
>>> d = nt.to_dict()
|
|
34
|
+
>>> d["x"]
|
|
35
|
+
10
|
|
36
|
+
>>> nt["z"] = [1, 2, 3]
|
|
37
|
+
TypeError
|
|
38
|
+
>>> nt.update("x", 20)
|
|
39
|
+
>>> nt.x
|
|
40
|
+
20
|
|
41
|
+
>>> nt.x = 20
|
|
42
|
+
Error: AttributeDoesNotSetValue
|
|
43
|
+
>>> del nt.x
|
|
44
|
+
Error: AttributeCannotBeDelete
|
|
45
|
+
"""
|
|
2
46
|
|
|
3
47
|
from typing import Any
|
|
4
48
|
|
|
@@ -9,7 +53,7 @@ from xloft.errors import (
|
|
|
9
53
|
|
|
10
54
|
|
|
11
55
|
class NamedTuple:
|
|
12
|
-
"""
|
|
56
|
+
"""This class imitates the behavior of the _named tuple_."""
|
|
13
57
|
|
|
14
58
|
VAR_NAME_FOR_KEYS_LIST: str = "_jWjSaNy1RbtQinsN_keys"
|
|
15
59
|
|
|
@@ -21,11 +65,34 @@ class NamedTuple:
|
|
|
21
65
|
self.__dict__[vnkl].append(name)
|
|
22
66
|
|
|
23
67
|
def __len__(self) -> int:
|
|
24
|
-
"""Get the number of elements.
|
|
68
|
+
"""Get the number of elements.
|
|
69
|
+
|
|
70
|
+
Examples:
|
|
71
|
+
>>> from xloft import NamedTuple
|
|
72
|
+
>>> nt = NamedTuple(x=10, y="Hello")
|
|
73
|
+
>>> len(nt)
|
|
74
|
+
2
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
The number of elements in the tuple.
|
|
78
|
+
"""
|
|
25
79
|
return len(self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST])
|
|
26
80
|
|
|
27
81
|
def __getattr__(self, name: str) -> Any:
|
|
28
|
-
"""Getter.
|
|
82
|
+
"""Getter.
|
|
83
|
+
|
|
84
|
+
Examples:
|
|
85
|
+
>>> from xloft import NamedTuple
|
|
86
|
+
>>> nt = NamedTuple(x=10, y="Hello")
|
|
87
|
+
>>> nt.x
|
|
88
|
+
10
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
name: Key name.
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
Value of key.
|
|
95
|
+
"""
|
|
29
96
|
return self.__dict__[name]
|
|
30
97
|
|
|
31
98
|
def __setattr__(self, name: str, value: Any) -> None:
|
|
@@ -37,16 +104,43 @@ class NamedTuple:
|
|
|
37
104
|
raise AttributeCannotBeDelete(name)
|
|
38
105
|
|
|
39
106
|
def get(self, key: str) -> Any:
|
|
40
|
-
"""Return the value for key if key is in the dictionary, else `None`.
|
|
107
|
+
"""Return the value for key if key is in the dictionary, else `None`.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
key: Key name.
|
|
111
|
+
|
|
112
|
+
Examples:
|
|
113
|
+
>>> from xloft import NamedTuple
|
|
114
|
+
>>> nt = NamedTuple(x=10, y="Hello")
|
|
115
|
+
>>> nt.get("x")
|
|
116
|
+
10
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
Value of key.
|
|
120
|
+
"""
|
|
41
121
|
value = self.__dict__.get(key)
|
|
42
122
|
if value is not None:
|
|
43
123
|
return value
|
|
44
124
|
return None
|
|
45
125
|
|
|
46
|
-
def update(self, key: str, value: Any) ->
|
|
126
|
+
def update(self, key: str, value: Any) -> None:
|
|
47
127
|
"""Update a value of key.
|
|
48
128
|
|
|
49
129
|
Attention: This is an uncharacteristic action for the type `tuple`.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
name: Key name.
|
|
133
|
+
value: Value of key.
|
|
134
|
+
|
|
135
|
+
Examples:
|
|
136
|
+
>>> from xloft import NamedTuple
|
|
137
|
+
>>> nt = NamedTuple(x=10, y="Hello")
|
|
138
|
+
>>> nt.update("x", 20)
|
|
139
|
+
>>> nt.x
|
|
140
|
+
20
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
None
|
|
50
144
|
"""
|
|
51
145
|
keys: list[str] = self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
|
|
52
146
|
if not key in keys:
|
|
@@ -55,30 +149,102 @@ class NamedTuple:
|
|
|
55
149
|
self.__dict__[key] = value
|
|
56
150
|
|
|
57
151
|
def to_dict(self) -> dict[str, Any]:
|
|
58
|
-
"""Convert to the dictionary.
|
|
59
|
-
|
|
60
|
-
|
|
152
|
+
"""Convert to the dictionary.
|
|
153
|
+
|
|
154
|
+
Examples:
|
|
155
|
+
>>> from xloft import NamedTuple
|
|
156
|
+
>>> nt = NamedTuple(x=10, y="Hello")
|
|
157
|
+
>>> d = nt.to_dict()
|
|
158
|
+
>>> d["x"]
|
|
159
|
+
10
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
Dictionary with keys and values of the tuple.
|
|
163
|
+
"""
|
|
164
|
+
attrs: dict[str, Any] = self.__dict__
|
|
165
|
+
keys: list[str] = attrs[self.__class__.VAR_NAME_FOR_KEYS_LIST]
|
|
166
|
+
return {key: attrs[key] for key in keys}
|
|
61
167
|
|
|
62
168
|
def items(self) -> list[tuple[str, Any]]:
|
|
63
|
-
"""Return a set-like object providing a view on the NamedTuple's items.
|
|
64
|
-
|
|
65
|
-
|
|
169
|
+
"""Return a set-like object providing a view on the NamedTuple's items.
|
|
170
|
+
|
|
171
|
+
Examples:
|
|
172
|
+
>>> from xloft import NamedTuple
|
|
173
|
+
>>> nt = NamedTuple(x=10, y="Hello")
|
|
174
|
+
>>> for key, val in nt.items():
|
|
175
|
+
... print(f"Key: {key}, Value: {val}")
|
|
176
|
+
"Key: x, Value: 10"
|
|
177
|
+
"Key: y, Value: Hello"
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
list[tuple[str, Any]]
|
|
181
|
+
"""
|
|
182
|
+
attrs: dict[str, Any] = self.__dict__
|
|
183
|
+
keys: list[str] = attrs[self.__class__.VAR_NAME_FOR_KEYS_LIST]
|
|
184
|
+
return [(key, attrs[key]) for key in keys]
|
|
66
185
|
|
|
67
186
|
def keys(self) -> list[str]:
|
|
68
|
-
"""Get a list of keys.
|
|
187
|
+
"""Get a list of keys.
|
|
188
|
+
|
|
189
|
+
Examples:
|
|
190
|
+
>>> from xloft import NamedTuple
|
|
191
|
+
>>> nt = NamedTuple(x=10, y="Hello")
|
|
192
|
+
>>> nt.keys()
|
|
193
|
+
["x", "y"]
|
|
194
|
+
|
|
195
|
+
Returns:
|
|
196
|
+
List of keys.
|
|
197
|
+
"""
|
|
69
198
|
return self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
|
|
70
199
|
|
|
71
200
|
def values(self) -> list[Any]:
|
|
72
|
-
"""Get a list of values.
|
|
73
|
-
|
|
74
|
-
|
|
201
|
+
"""Get a list of values.
|
|
202
|
+
|
|
203
|
+
Examples:
|
|
204
|
+
>>> from xloft import NamedTuple
|
|
205
|
+
>>> nt = NamedTuple(x=10, y="Hello")
|
|
206
|
+
>>> nt.values()
|
|
207
|
+
[10, "Hello"]
|
|
208
|
+
|
|
209
|
+
Returns:
|
|
210
|
+
List of values.
|
|
211
|
+
"""
|
|
212
|
+
attrs: dict[str, Any] = self.__dict__
|
|
213
|
+
keys: list[str] = attrs[self.__class__.VAR_NAME_FOR_KEYS_LIST]
|
|
214
|
+
return [attrs[key] for key in keys]
|
|
75
215
|
|
|
76
216
|
def has_key(self, key: str) -> bool:
|
|
77
|
-
"""Returns True if the key exists, otherwise False.
|
|
217
|
+
"""Returns True if the key exists, otherwise False.
|
|
218
|
+
|
|
219
|
+
Args:
|
|
220
|
+
key: Key name.
|
|
221
|
+
|
|
222
|
+
Examples:
|
|
223
|
+
>>> from xloft import NamedTuple
|
|
224
|
+
>>> nt = NamedTuple(x=10, y="Hello")
|
|
225
|
+
>>> nt.has_key("x")
|
|
226
|
+
True
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
True if the key exists, otherwise False.
|
|
230
|
+
"""
|
|
78
231
|
keys: list[str] = self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
|
|
79
232
|
return key in keys
|
|
80
233
|
|
|
81
234
|
def has_value(self, value: Any) -> bool:
|
|
82
|
-
"""Returns True if the value exists, otherwise False.
|
|
235
|
+
"""Returns True if the value exists, otherwise False.
|
|
236
|
+
|
|
237
|
+
Args:
|
|
238
|
+
value: Value of key.
|
|
239
|
+
|
|
240
|
+
Examples:
|
|
241
|
+
>>> from xloft import NamedTuple
|
|
242
|
+
>>> nt = NamedTuple(x=10, y="Hello")
|
|
243
|
+
>>> nt.has_value(10)
|
|
244
|
+
True
|
|
245
|
+
|
|
246
|
+
Returns:
|
|
247
|
+
True if the value exists, otherwise False.
|
|
248
|
+
"""
|
|
83
249
|
values = self.values()
|
|
84
250
|
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.10
|
|
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
|
|
@@ -107,12 +107,6 @@ nt.get("x") # => 10
|
|
|
107
107
|
nt.get("y") # => "Hello"
|
|
108
108
|
nt.get("z") # => None
|
|
109
109
|
|
|
110
|
-
nt.update("x", 20)
|
|
111
|
-
nt.update("y", "Hi")
|
|
112
|
-
nt.x # => 20
|
|
113
|
-
nt.y # => "Hi"
|
|
114
|
-
nt.update("z", [1, 2, 3]) # => raise: KeyError
|
|
115
|
-
|
|
116
110
|
d = nt.to_dict()
|
|
117
111
|
d["x"] # => 10
|
|
118
112
|
d["y"] # => "Hello"
|
|
@@ -127,6 +121,12 @@ nt["x"] = 20 # => TypeError
|
|
|
127
121
|
nt["y"] = "Hi" # => TypeError
|
|
128
122
|
nt["z"] = [1, 2, 3] # => TypeError
|
|
129
123
|
|
|
124
|
+
nt.update("x", 20)
|
|
125
|
+
nt.update("y", "Hi")
|
|
126
|
+
nt.x # => 20
|
|
127
|
+
nt.y # => "Hi"
|
|
128
|
+
nt.update("z", [1, 2, 3]) # => raise: KeyError
|
|
129
|
+
|
|
130
130
|
nt.x = 20 # => raise: AttributeDoesNotSetValue
|
|
131
131
|
nt.y = "Hi" # => raise: AttributeDoesNotSetValue
|
|
132
132
|
nt.z = [1, 2, 3] # => raise: AttributeDoesNotSetValue
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
xloft/__init__.py,sha256=YtzkovVqW8hLxBXxM0U7K_qqfU8XBJ1pzX6tAgTUNFw,215
|
|
2
|
+
xloft/errors.py,sha256=GYXvi2l01VUDQSs6skiOfQsKLF6tFuUhJMqNkL7BJNI,857
|
|
3
|
+
xloft/namedtuple.py,sha256=yVeP4UayzPaxi0NmpB__ILmw9sZbZpy9v5hEps1bv7E,6740
|
|
4
|
+
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
xloft-0.1.10.dist-info/METADATA,sha256=7ckc9ufBvrltvJA5Y4fC3YPI3BS6NbESt6-UoR0vk00,5678
|
|
6
|
+
xloft-0.1.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
xloft-0.1.10.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
+
xloft-0.1.10.dist-info/RECORD,,
|
xloft-0.1.9.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=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,,
|
|
File without changes
|
|
File without changes
|