xloft 0.1.6__py3-none-any.whl → 0.1.8__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,9 +11,17 @@ 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
17
+ self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST] = []
15
18
  for name, value in kwargs.items():
16
19
  self.__dict__[name] = value
20
+ self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST].append(name)
21
+
22
+ def __len__(self) -> int:
23
+ """Get the number of elements."""
24
+ return len(self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST])
17
25
 
18
26
  def __getattr__(self, name: str) -> Any:
19
27
  """Getter."""
@@ -27,24 +35,49 @@ class NamedTuple:
27
35
  """Fail Deleter."""
28
36
  raise AttributeCannotBeDelete(name)
29
37
 
30
- def get(self, key: str, default: Any | None = None) -> Any | None:
31
- """Return the value for key if key is in the dictionary, else default."""
38
+ def get(self, key: str) -> Any:
39
+ """Return the value for key if key is in the dictionary, else `None`."""
32
40
  value = self.__dict__.get(key)
33
41
  if value is not None:
34
42
  return value
35
- return default
43
+ return None
36
44
 
37
45
  def update(self, key: str, value: Any) -> Any:
38
46
  """Update a value of key.
39
47
 
40
48
  Attention: This is an uncharacteristic action for the type `tuple`.
41
49
  """
50
+ keys: list[str] = self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST]
51
+ if not key in keys:
52
+ err_msg = f"The key `{key}` is missing!"
53
+ raise KeyError(err_msg)
42
54
  self.__dict__[key] = value
43
55
 
44
56
  def to_dict(self) -> dict[str, Any]:
45
57
  """Convert to the dictionary."""
46
- return {key: value for key, value in self.__dict__.items() if not callable(value)}
58
+ keys: list[str] = self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST]
59
+ return {key: self.__dict__[key] for key in keys}
47
60
 
48
61
  def items(self) -> list[tuple[str, Any]]:
49
62
  """Return a set-like object providing a view on the NamedTuple's items."""
50
- return [(key, value) for key, value in self.__dict__.items() if not callable(value)]
63
+ keys: list[str] = self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST]
64
+ return [(key, self.__dict__[key]) for key in keys]
65
+
66
+ def keys(self) -> list[str]:
67
+ """Get a list of keys."""
68
+ return self.__dict__[NamedTuple.VAR_NAME_FOR_KEYS_LIST]
69
+
70
+ 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]
74
+
75
+ 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]
78
+ return key in keys
79
+
80
+ def has_value(self, value: Any) -> bool:
81
+ """Returns True if the value exists, otherwise False."""
82
+ values = self.values()
83
+ return value in values
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xloft
3
- Version: 0.1.6
3
+ Version: 0.1.8
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
@@ -91,26 +91,27 @@ nt.x # => 10
91
91
  nt.y # => "Hello"
92
92
  nt.z # => raise: KeyError
93
93
 
94
- nt["x"] # => raise: KeyError
95
- nt["y"] # => raise: KeyError
96
- nt["x"] = 20 # => TypeError
97
- nt["y"] = "Hi" # => TypeError
94
+ len(nt) # => 2
95
+ nt.keys() # => ["x", "y"]
96
+ nt.values() # => [10, "Hello"]
97
+
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
98
105
 
99
106
  nt.get("x") # => 10
100
107
  nt.get("y") # => "Hello"
101
108
  nt.get("z") # => None
102
- nt.get("z", [1, 2, 3] ) # => [1, 2, 3]
103
-
104
- nt.x = 20 # => raise: AttributeDoesNotSetValue
105
- nt.y = "Hi" # => raise: AttributeDoesNotSetValue
106
- nt.z = [1, 2, 3] # => raise: AttributeDoesNotSetValue
107
109
 
108
110
  nt.update("x", 20)
109
111
  nt.update("y", "Hi")
110
112
  nt.x # => 20
111
113
  nt.y # => "Hi"
112
- nt.update("z", [1, 2, 3])
113
- nt.z # => [1, 2, 3]
114
+ nt.update("z", [1, 2, 3]) # => raise: KeyError
114
115
 
115
116
  d = nt.to_dict()
116
117
  d["x"] # => 10
@@ -119,6 +120,17 @@ d["y"] # => "Hello"
119
120
  for key, val in nt.items():
120
121
  print(f"Key: {key}, Value: {val}")
121
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
+
122
134
  del nt.x # => raise: AttributeCannotBeDelete
123
135
  del nt.y # => raise: AttributeCannotBeDelete
124
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=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,,
@@ -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=05XP8vgA9_AuSyQyx2G4Wbbf2ZiPffNBjtB-w_VDAe0,1612
4
- xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- xloft-0.1.6.dist-info/METADATA,sha256=RbJLzlYiegynxSn89iMTbZV2ykpFvwa4-hqu7l4iDWc,5393
6
- xloft-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- xloft-0.1.6.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
- xloft-0.1.6.dist-info/RECORD,,
File without changes