xloft 0.1.9__py3-none-any.whl → 0.1.11__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,7 +53,7 @@ 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
 
@@ -21,32 +65,82 @@ 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:
32
- """Fail Setter."""
99
+ """Blocked Setter."""
33
100
  raise AttributeDoesNotSetValue(name)
34
101
 
35
102
  def __delattr__(self, name: str) -> None:
36
- """Fail Deleter."""
103
+ """Blocked Deleter."""
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) -> 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
+ key: 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
- keys: list[str] = self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
60
- 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}
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
- keys: list[str] = self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
65
- 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]
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
- keys: list[str] = self.__dict__[self.__class__.VAR_NAME_FOR_KEYS_LIST]
74
- 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]
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.9
3
+ Version: 0.1.11
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
@@ -66,6 +66,10 @@ Description-Content-Type: text/markdown
66
66
 
67
67
  ##
68
68
 
69
+ ## Documentation
70
+
71
+ Online browsable documentation is available at [https://kebasyaty.github.io/xloft/](https://kebasyaty.github.io/xloft/ "Documentation").
72
+
69
73
  ## Requirements
70
74
 
71
75
  [View the list of requirements.](https://github.com/kebasyaty/xloft/blob/main/REQUIREMENTS.md "View the list of requirements.")
@@ -107,12 +111,6 @@ nt.get("x") # => 10
107
111
  nt.get("y") # => "Hello"
108
112
  nt.get("z") # => None
109
113
 
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
114
  d = nt.to_dict()
117
115
  d["x"] # => 10
118
116
  d["y"] # => "Hello"
@@ -127,6 +125,12 @@ nt["x"] = 20 # => TypeError
127
125
  nt["y"] = "Hi" # => TypeError
128
126
  nt["z"] = [1, 2, 3] # => TypeError
129
127
 
128
+ nt.update("x", 20)
129
+ nt.update("y", "Hi")
130
+ nt.x # => 20
131
+ nt.y # => "Hi"
132
+ nt.update("z", [1, 2, 3]) # => raise: KeyError
133
+
130
134
  nt.x = 20 # => raise: AttributeDoesNotSetValue
131
135
  nt.y = "Hi" # => raise: AttributeDoesNotSetValue
132
136
  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=NT98kIuVoPf6LHHVaPAnveK9KdeBjxGlO_AZtpCnkWM,6745
4
+ xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ xloft-0.1.11.dist-info/METADATA,sha256=NAuMTBKl9QAEiTEv7WHzxl7wPASqLDYn_P5YSjHVhDg,5834
6
+ xloft-0.1.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ xloft-0.1.11.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
+ xloft-0.1.11.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=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