xloft 0.1.8__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 CHANGED
@@ -1,4 +1,9 @@
1
- """(XLOFT) X-Library of tools."""
1
+ """(XLOFT) X-Library of tools.
2
+
3
+ Modules exported by this package:
4
+
5
+ - `NamedTuple`: Class imitates the behavior of the _named tuple_.
6
+ """
2
7
 
3
8
  __all__ = ("NamedTuple",)
4
9
 
xloft/namedtuple.py CHANGED
@@ -1,4 +1,48 @@
1
- """Named Tuple."""
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,22 +53,46 @@ from xloft.errors import (
9
53
 
10
54
 
11
55
  class NamedTuple:
12
- """Named Tuple."""
56
+ """This class imitates the behavior of the _named tuple_."""
13
57
 
14
58
  VAR_NAME_FOR_KEYS_LIST: str = "_jWjSaNy1RbtQinsN_keys"
15
59
 
16
60
  def __init__(self, **kwargs: dict[str, Any]) -> None: # noqa: D107
17
- self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST] = []
61
+ vnkl = self.__class__.VAR_NAME_FOR_KEYS_LIST
62
+ self.__dict__[vnkl] = []
18
63
  for name, value in kwargs.items():
19
64
  self.__dict__[name] = value
20
- self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST].append(name)
65
+ self.__dict__[vnkl].append(name)
21
66
 
22
67
  def __len__(self) -> int:
23
- """Get the number of elements."""
24
- return len(self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST])
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
+ """
79
+ return len(self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST])
25
80
 
26
81
  def __getattr__(self, name: str) -> Any:
27
- """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
+ """
28
96
  return self.__dict__[name]
29
97
 
30
98
  def __setattr__(self, name: str, value: Any) -> None:
@@ -36,48 +104,147 @@ class NamedTuple:
36
104
  raise AttributeCannotBeDelete(name)
37
105
 
38
106
  def get(self, key: str) -> Any:
39
- """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
+ """
40
121
  value = self.__dict__.get(key)
41
122
  if value is not None:
42
123
  return value
43
124
  return None
44
125
 
45
- def update(self, key: str, value: Any) -> Any:
126
+ def update(self, key: str, value: Any) -> None:
46
127
  """Update a value of key.
47
128
 
48
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
49
144
  """
50
- keys: list[str] = self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST]
145
+ keys: list[str] = self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
51
146
  if not key in keys:
52
147
  err_msg = f"The key `{key}` is missing!"
53
148
  raise KeyError(err_msg)
54
149
  self.__dict__[key] = value
55
150
 
56
151
  def to_dict(self) -> dict[str, Any]:
57
- """Convert to the dictionary."""
58
- keys: list[str] = self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST]
59
- return {key: self.__dict__[key] for key in keys}
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}
60
167
 
61
168
  def items(self) -> list[tuple[str, Any]]:
62
- """Return a set-like object providing a view on the NamedTuple's items."""
63
- keys: list[str] = self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST]
64
- return [(key, self.__dict__[key]) for key in keys]
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]
65
185
 
66
186
  def keys(self) -> list[str]:
67
- """Get a list of keys."""
68
- return self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST]
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
+ """
198
+ return self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
69
199
 
70
200
  def values(self) -> list[Any]:
71
- """Get a list of values."""
72
- keys: list[str] = self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST]
73
- return [self.__dict__[key] for key in keys]
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]
74
215
 
75
216
  def has_key(self, key: str) -> bool:
76
- """Returns True if the key exists, otherwise False."""
77
- keys: list[str] = self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST]
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
+ """
231
+ keys: list[str] = self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
78
232
  return key in keys
79
233
 
80
234
  def has_value(self, value: Any) -> bool:
81
- """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
+ """
82
249
  values = self.values()
83
250
  return value in values
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xloft
3
- Version: 0.1.8
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,,
@@ -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=PVj9DJDo01mU91EgBcyIx3XFRs0iKTjEv_wfq1A1CKA,2929
4
- xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- xloft-0.1.8.dist-info/METADATA,sha256=ga-tZTK076ryrQuqiFFMn0EiBs-9Nary09uycdwt-tQ,5677
6
- xloft-0.1.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- xloft-0.1.8.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
- xloft-0.1.8.dist-info/RECORD,,
File without changes