swizzle 2.2.1__tar.gz → 2.3.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: swizzle
3
- Version: 2.2.1
3
+ Version: 2.3.0
4
4
  Summary: Swizzle enables the retrieval of multiple attributes, similar to swizzling in computer graphics.
5
5
  Home-page: https://github.com/janthmueller/swizzle
6
6
  Author: Jan T. Müller
@@ -17,6 +17,17 @@ Classifier: Programming Language :: Python :: 3 :: Only
17
17
  Requires-Python: >=3.6
18
18
  Description-Content-Type: text/markdown
19
19
  License-File: LICENSE
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: classifier
23
+ Dynamic: description
24
+ Dynamic: description-content-type
25
+ Dynamic: home-page
26
+ Dynamic: license
27
+ Dynamic: license-file
28
+ Dynamic: project-url
29
+ Dynamic: requires-python
30
+ Dynamic: summary
20
31
 
21
32
  # Swizzle
22
33
 
@@ -14,7 +14,7 @@ except ImportError:
14
14
 
15
15
  _type = builtins.type
16
16
 
17
- __version__ = "2.2.1"
17
+ __version__ = "2.3.0"
18
18
 
19
19
  MISSING = object()
20
20
 
@@ -43,7 +43,7 @@ def swizzledtuple(typename, field_names, *, rename=False, defaults=None, module=
43
43
  to the order given in `field_names`.
44
44
  sep (str, optional): A separator string that customizes the structure of attribute
45
45
  access. If provided, this sep allows attributes to be accessed by combining field
46
- names with the sep in between them. Defaults to no sep.
46
+ names with the sep in between them. Defaults to None.
47
47
 
48
48
  Returns:
49
49
  type: A new subclass of `tuple` with named fields and customized attribute access.
@@ -196,6 +196,40 @@ def swizzledtuple(typename, field_names, *, rename=False, defaults=None, module=
196
196
  def __getattribute__(self, attr_name):
197
197
  return super(_tuple, self).__getattribute__(attr_name)
198
198
 
199
+ # def __getitem__(self, index):
200
+ # a_names = arrange_names[index]
201
+ # _sep = '' if sep is None else sep
202
+ # return getattr(self, _sep.join(a_names))
203
+
204
+ def __getitem__(self, index):
205
+ if not isinstance(index, slice):
206
+ return _tuple.__getitem__(self, index)
207
+
208
+ selected_indices = arrange_indices[index]
209
+ selected_values = _tuple.__getitem__(self, index)
210
+
211
+ seen = set()
212
+ filtered = [
213
+ (i, v, field_names[i])
214
+ for i, v in zip(selected_indices, selected_values)
215
+ if not (i in seen or seen.add(i))
216
+ ]
217
+
218
+ if filtered:
219
+ _, filtered_values, filtered_names = zip(*filtered)
220
+ else:
221
+ filtered_values, filtered_names = (), ()
222
+
223
+ return swizzledtuple(
224
+ typename,
225
+ filtered_names,
226
+ rename=rename,
227
+ defaults=filtered_values,
228
+ module=module,
229
+ arrange_names=arrange_names[index],
230
+ sep=sep
231
+ )()
232
+
199
233
 
200
234
 
201
235
  for method in (
@@ -206,6 +240,7 @@ def swizzledtuple(typename, field_names, *, rename=False, defaults=None, module=
206
240
  _asdict,
207
241
  __getnewargs__,
208
242
  __getattribute__,
243
+ __getitem__
209
244
  ):
210
245
  method.__qualname__ = f'{typename}.{method.__name__}'
211
246
 
@@ -220,7 +255,8 @@ def swizzledtuple(typename, field_names, *, rename=False, defaults=None, module=
220
255
  '__repr__': __repr__,
221
256
  '_asdict': _asdict,
222
257
  '__getnewargs__': __getnewargs__,
223
- '__getattribute__': __getattribute__
258
+ '__getattribute__': __getattribute__,
259
+ '__getitem__': __getitem__
224
260
  }
225
261
  seen = set()
226
262
  for index, name in enumerate(arrange_names):
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: swizzle
3
- Version: 2.2.1
3
+ Version: 2.3.0
4
4
  Summary: Swizzle enables the retrieval of multiple attributes, similar to swizzling in computer graphics.
5
5
  Home-page: https://github.com/janthmueller/swizzle
6
6
  Author: Jan T. Müller
@@ -17,6 +17,17 @@ Classifier: Programming Language :: Python :: 3 :: Only
17
17
  Requires-Python: >=3.6
18
18
  Description-Content-Type: text/markdown
19
19
  License-File: LICENSE
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: classifier
23
+ Dynamic: description
24
+ Dynamic: description-content-type
25
+ Dynamic: home-page
26
+ Dynamic: license
27
+ Dynamic: license-file
28
+ Dynamic: project-url
29
+ Dynamic: requires-python
30
+ Dynamic: summary
20
31
 
21
32
  # Swizzle
22
33
 
File without changes
File without changes
File without changes
File without changes