swizzle 2.2.0__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.
swizzle-2.3.0/PKG-INFO ADDED
@@ -0,0 +1,195 @@
1
+ Metadata-Version: 2.4
2
+ Name: swizzle
3
+ Version: 2.3.0
4
+ Summary: Swizzle enables the retrieval of multiple attributes, similar to swizzling in computer graphics.
5
+ Home-page: https://github.com/janthmueller/swizzle
6
+ Author: Jan T. Müller
7
+ Author-email: mail@jantmueller.com
8
+ License: MIT
9
+ Project-URL: Documentation, https://github.com/janthmueller/swizzle/blob/main/README.md
10
+ Project-URL: Source, https://github.com/janthmueller/swizzle
11
+ Project-URL: Tracker, https://github.com/janthmueller/swizzle/issues
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Requires-Python: >=3.6
18
+ Description-Content-Type: text/markdown
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
31
+
32
+ # Swizzle
33
+
34
+ [![PyPI Latest Release](https://img.shields.io/pypi/v/swizzle.svg)](https://pypi.org/project/swizzle/)
35
+ [![Pepy Total Downloads](https://img.shields.io/pepy/dt/swizzle)](https://pepy.tech/project/swizzle)
36
+ [![GitHub License](https://img.shields.io/github/license/janthmueller/swizzle)](https://github.com/janthmueller/swizzle/blob/main/LICENSE)
37
+
38
+ ## Introduction
39
+
40
+ **Swizzle** is a Python package that enhances attribute access, allowing for flexible retrieval of multiple attributes based on specified arrangements of their names.
41
+
42
+ Managing object attributes efficiently can sometimes become cumbersome, especially when you need to access multiple attributes in various combinations. Swizzle simplifies this process by extending Python's attribute access mechanisms, enabling you to access attributes in any order or combination without explicitly referencing the instance every time or defining new methods for each combination.
43
+
44
+ ## Features
45
+
46
+ - **Dynamic Attribute Access**: Retrieve multiple attributes in any specified arrangement.
47
+ - **Reduced Boilerplate**: Eliminate redundant code by avoiding multiple getter methods.
48
+ - **Integration with Existing Classes**: Works seamlessly with regular classes, `dataclass`, and even `Enum` types.
49
+ - **Customizable Matching**: Control attribute matching behavior with parameters like `sep`.
50
+
51
+ ## Installation
52
+
53
+ ### From PyPI
54
+
55
+ Install Swizzle via pip:
56
+
57
+ ```bash
58
+ pip install swizzle
59
+ ```
60
+
61
+ ### From GitHub
62
+
63
+ Install the latest version directly from GitHub:
64
+
65
+ ```bash
66
+ pip install git+https://github.com/janthmueller/swizzle.git
67
+ ```
68
+
69
+ ## Getting Started
70
+
71
+ ### Basic Usage with the `@swizzle` Decorator
72
+
73
+ Apply the `@swizzle` decorator to your class:
74
+
75
+ ```python
76
+ import swizzle
77
+
78
+ @swizzle
79
+ class Vector:
80
+ def __init__(self, x, y, z):
81
+ self.x = x
82
+ self.y = y
83
+ self.z = z
84
+
85
+ v = Vector(1, 2, 3)
86
+
87
+ # Access attributes in different orders
88
+ print(v.yzx) # Output: Vector(y=2, z=3, x=1)
89
+ ```
90
+
91
+ ### Using Swizzle with `dataclass`
92
+
93
+ Swizzle integrates smoothly with Python's `dataclass`:
94
+
95
+ ```python
96
+ import swizzle
97
+ from dataclasses import dataclass
98
+
99
+ @swizzle
100
+ @dataclass
101
+ class Point:
102
+ x: int
103
+ y: int
104
+ z: int
105
+
106
+ p = Point(1, 2, 3)
107
+
108
+ print(p.zxy) # Output: Point(z=3, x=1, y=2)
109
+ ```
110
+
111
+ ### Swizzling Enums with `meta=True`
112
+
113
+ Enable attribute swizzling directly on the class by setting `meta=True`:
114
+
115
+ ```python
116
+ import swizzle
117
+ from enum import IntEnum
118
+
119
+ @swizzle(meta=True)
120
+ class Axis(IntEnum):
121
+ X = 1
122
+ Y = 2
123
+ Z = 3
124
+
125
+ print(Axis.YXZ) # Output: Axis(Y=<Axis.Y: 2>, X=<Axis.X: 1>, Z=<Axis.Z: 3>)
126
+ ```
127
+
128
+ ## Advanced Usage
129
+
130
+ ### Swizzled Named Tuples with `swizzledtuple`
131
+
132
+ Create swizzled named tuples inspired by `namedtuple`:
133
+
134
+ ```python
135
+ from swizzle import swizzledtuple
136
+
137
+ Vector = swizzledtuple('Vector', 'x y z')
138
+
139
+ v = Vector(1, 2, 3)
140
+
141
+ print(v.yzx) # Output: Vector(y=2, z=3, x=1)
142
+ print(v.yzx.xxzyzz) # Output: Vector(x=1, x=1, z=3, y=2, z=3, z=3)
143
+ ```
144
+
145
+ ### Custom Separators
146
+
147
+ Attributes are matched from left to right, starting with the longest substring match. This behavior can be controlled by the `sep` argument in the swizzle decorator:
148
+
149
+ ```python
150
+ import swizzle
151
+
152
+ @swizzle(meta=True, sep='_')
153
+ class BoundingBox:
154
+ x = 10
155
+ y = 20
156
+ w = 100
157
+ h = 200
158
+
159
+ print(BoundingBox.x_y_w_h) # Output: BoundingBox(x=10, y=20, w=100, h=200)
160
+ ```
161
+
162
+ ## Understanding Swizzling
163
+
164
+ Swizzling allows:
165
+
166
+ - **Rearrangement**: Access attributes in any order (e.g., `v.yzx`).
167
+ - **Duplication**: Access the same attribute multiple times (e.g., `v.xxy`).
168
+ - **Dynamic Composition**: Create new instances with desired attribute arrangements.
169
+
170
+ ## Benefits
171
+
172
+ - **Efficient Attribute Management**: Simplify complex attribute combinations.
173
+ - **Dynamic Access Patterns**: No need for predefined attribute combinations.
174
+ - **Cleaner Codebase**: Reduce redundancy and improve maintainability.
175
+ - **Enhanced Readability**: Code becomes more expressive and intuitive.
176
+
177
+ ## Conclusion
178
+
179
+ Swizzle is a powerful tool that streamlines attribute management in Python. It offers a flexible and efficient way to access and manipulate object attributes, making your code cleaner and more maintainable.
180
+
181
+ ## License
182
+
183
+ This project is licensed under the terms of the MIT license. See the [LICENSE](https://github.com/janthmueller/swizzle/blob/main/LICENSE) file for details.
184
+
185
+ ## Contributions
186
+
187
+ Contributions are welcome! Feel free to submit a Pull Request or open an Issue on GitHub.
188
+
189
+ ## Acknowledgments
190
+
191
+ Inspired by swizzling in graphics programming, Swizzle brings similar flexibility to Python attribute management.
192
+
193
+ ---
194
+
195
+ Give Swizzle a try and see how it can simplify your Python projects!
@@ -0,0 +1,164 @@
1
+ # Swizzle
2
+
3
+ [![PyPI Latest Release](https://img.shields.io/pypi/v/swizzle.svg)](https://pypi.org/project/swizzle/)
4
+ [![Pepy Total Downloads](https://img.shields.io/pepy/dt/swizzle)](https://pepy.tech/project/swizzle)
5
+ [![GitHub License](https://img.shields.io/github/license/janthmueller/swizzle)](https://github.com/janthmueller/swizzle/blob/main/LICENSE)
6
+
7
+ ## Introduction
8
+
9
+ **Swizzle** is a Python package that enhances attribute access, allowing for flexible retrieval of multiple attributes based on specified arrangements of their names.
10
+
11
+ Managing object attributes efficiently can sometimes become cumbersome, especially when you need to access multiple attributes in various combinations. Swizzle simplifies this process by extending Python's attribute access mechanisms, enabling you to access attributes in any order or combination without explicitly referencing the instance every time or defining new methods for each combination.
12
+
13
+ ## Features
14
+
15
+ - **Dynamic Attribute Access**: Retrieve multiple attributes in any specified arrangement.
16
+ - **Reduced Boilerplate**: Eliminate redundant code by avoiding multiple getter methods.
17
+ - **Integration with Existing Classes**: Works seamlessly with regular classes, `dataclass`, and even `Enum` types.
18
+ - **Customizable Matching**: Control attribute matching behavior with parameters like `sep`.
19
+
20
+ ## Installation
21
+
22
+ ### From PyPI
23
+
24
+ Install Swizzle via pip:
25
+
26
+ ```bash
27
+ pip install swizzle
28
+ ```
29
+
30
+ ### From GitHub
31
+
32
+ Install the latest version directly from GitHub:
33
+
34
+ ```bash
35
+ pip install git+https://github.com/janthmueller/swizzle.git
36
+ ```
37
+
38
+ ## Getting Started
39
+
40
+ ### Basic Usage with the `@swizzle` Decorator
41
+
42
+ Apply the `@swizzle` decorator to your class:
43
+
44
+ ```python
45
+ import swizzle
46
+
47
+ @swizzle
48
+ class Vector:
49
+ def __init__(self, x, y, z):
50
+ self.x = x
51
+ self.y = y
52
+ self.z = z
53
+
54
+ v = Vector(1, 2, 3)
55
+
56
+ # Access attributes in different orders
57
+ print(v.yzx) # Output: Vector(y=2, z=3, x=1)
58
+ ```
59
+
60
+ ### Using Swizzle with `dataclass`
61
+
62
+ Swizzle integrates smoothly with Python's `dataclass`:
63
+
64
+ ```python
65
+ import swizzle
66
+ from dataclasses import dataclass
67
+
68
+ @swizzle
69
+ @dataclass
70
+ class Point:
71
+ x: int
72
+ y: int
73
+ z: int
74
+
75
+ p = Point(1, 2, 3)
76
+
77
+ print(p.zxy) # Output: Point(z=3, x=1, y=2)
78
+ ```
79
+
80
+ ### Swizzling Enums with `meta=True`
81
+
82
+ Enable attribute swizzling directly on the class by setting `meta=True`:
83
+
84
+ ```python
85
+ import swizzle
86
+ from enum import IntEnum
87
+
88
+ @swizzle(meta=True)
89
+ class Axis(IntEnum):
90
+ X = 1
91
+ Y = 2
92
+ Z = 3
93
+
94
+ print(Axis.YXZ) # Output: Axis(Y=<Axis.Y: 2>, X=<Axis.X: 1>, Z=<Axis.Z: 3>)
95
+ ```
96
+
97
+ ## Advanced Usage
98
+
99
+ ### Swizzled Named Tuples with `swizzledtuple`
100
+
101
+ Create swizzled named tuples inspired by `namedtuple`:
102
+
103
+ ```python
104
+ from swizzle import swizzledtuple
105
+
106
+ Vector = swizzledtuple('Vector', 'x y z')
107
+
108
+ v = Vector(1, 2, 3)
109
+
110
+ print(v.yzx) # Output: Vector(y=2, z=3, x=1)
111
+ print(v.yzx.xxzyzz) # Output: Vector(x=1, x=1, z=3, y=2, z=3, z=3)
112
+ ```
113
+
114
+ ### Custom Separators
115
+
116
+ Attributes are matched from left to right, starting with the longest substring match. This behavior can be controlled by the `sep` argument in the swizzle decorator:
117
+
118
+ ```python
119
+ import swizzle
120
+
121
+ @swizzle(meta=True, sep='_')
122
+ class BoundingBox:
123
+ x = 10
124
+ y = 20
125
+ w = 100
126
+ h = 200
127
+
128
+ print(BoundingBox.x_y_w_h) # Output: BoundingBox(x=10, y=20, w=100, h=200)
129
+ ```
130
+
131
+ ## Understanding Swizzling
132
+
133
+ Swizzling allows:
134
+
135
+ - **Rearrangement**: Access attributes in any order (e.g., `v.yzx`).
136
+ - **Duplication**: Access the same attribute multiple times (e.g., `v.xxy`).
137
+ - **Dynamic Composition**: Create new instances with desired attribute arrangements.
138
+
139
+ ## Benefits
140
+
141
+ - **Efficient Attribute Management**: Simplify complex attribute combinations.
142
+ - **Dynamic Access Patterns**: No need for predefined attribute combinations.
143
+ - **Cleaner Codebase**: Reduce redundancy and improve maintainability.
144
+ - **Enhanced Readability**: Code becomes more expressive and intuitive.
145
+
146
+ ## Conclusion
147
+
148
+ Swizzle is a powerful tool that streamlines attribute management in Python. It offers a flexible and efficient way to access and manipulate object attributes, making your code cleaner and more maintainable.
149
+
150
+ ## License
151
+
152
+ This project is licensed under the terms of the MIT license. See the [LICENSE](https://github.com/janthmueller/swizzle/blob/main/LICENSE) file for details.
153
+
154
+ ## Contributions
155
+
156
+ Contributions are welcome! Feel free to submit a Pull Request or open an Issue on GitHub.
157
+
158
+ ## Acknowledgments
159
+
160
+ Inspired by swizzling in graphics programming, Swizzle brings similar flexibility to Python attribute management.
161
+
162
+ ---
163
+
164
+ Give Swizzle a try and see how it can simplify your Python projects!
@@ -14,7 +14,7 @@ except ImportError:
14
14
 
15
15
  _type = builtins.type
16
16
 
17
- __version__ = "2.2.0"
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):
@@ -0,0 +1,195 @@
1
+ Metadata-Version: 2.4
2
+ Name: swizzle
3
+ Version: 2.3.0
4
+ Summary: Swizzle enables the retrieval of multiple attributes, similar to swizzling in computer graphics.
5
+ Home-page: https://github.com/janthmueller/swizzle
6
+ Author: Jan T. Müller
7
+ Author-email: mail@jantmueller.com
8
+ License: MIT
9
+ Project-URL: Documentation, https://github.com/janthmueller/swizzle/blob/main/README.md
10
+ Project-URL: Source, https://github.com/janthmueller/swizzle
11
+ Project-URL: Tracker, https://github.com/janthmueller/swizzle/issues
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Requires-Python: >=3.6
18
+ Description-Content-Type: text/markdown
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
31
+
32
+ # Swizzle
33
+
34
+ [![PyPI Latest Release](https://img.shields.io/pypi/v/swizzle.svg)](https://pypi.org/project/swizzle/)
35
+ [![Pepy Total Downloads](https://img.shields.io/pepy/dt/swizzle)](https://pepy.tech/project/swizzle)
36
+ [![GitHub License](https://img.shields.io/github/license/janthmueller/swizzle)](https://github.com/janthmueller/swizzle/blob/main/LICENSE)
37
+
38
+ ## Introduction
39
+
40
+ **Swizzle** is a Python package that enhances attribute access, allowing for flexible retrieval of multiple attributes based on specified arrangements of their names.
41
+
42
+ Managing object attributes efficiently can sometimes become cumbersome, especially when you need to access multiple attributes in various combinations. Swizzle simplifies this process by extending Python's attribute access mechanisms, enabling you to access attributes in any order or combination without explicitly referencing the instance every time or defining new methods for each combination.
43
+
44
+ ## Features
45
+
46
+ - **Dynamic Attribute Access**: Retrieve multiple attributes in any specified arrangement.
47
+ - **Reduced Boilerplate**: Eliminate redundant code by avoiding multiple getter methods.
48
+ - **Integration with Existing Classes**: Works seamlessly with regular classes, `dataclass`, and even `Enum` types.
49
+ - **Customizable Matching**: Control attribute matching behavior with parameters like `sep`.
50
+
51
+ ## Installation
52
+
53
+ ### From PyPI
54
+
55
+ Install Swizzle via pip:
56
+
57
+ ```bash
58
+ pip install swizzle
59
+ ```
60
+
61
+ ### From GitHub
62
+
63
+ Install the latest version directly from GitHub:
64
+
65
+ ```bash
66
+ pip install git+https://github.com/janthmueller/swizzle.git
67
+ ```
68
+
69
+ ## Getting Started
70
+
71
+ ### Basic Usage with the `@swizzle` Decorator
72
+
73
+ Apply the `@swizzle` decorator to your class:
74
+
75
+ ```python
76
+ import swizzle
77
+
78
+ @swizzle
79
+ class Vector:
80
+ def __init__(self, x, y, z):
81
+ self.x = x
82
+ self.y = y
83
+ self.z = z
84
+
85
+ v = Vector(1, 2, 3)
86
+
87
+ # Access attributes in different orders
88
+ print(v.yzx) # Output: Vector(y=2, z=3, x=1)
89
+ ```
90
+
91
+ ### Using Swizzle with `dataclass`
92
+
93
+ Swizzle integrates smoothly with Python's `dataclass`:
94
+
95
+ ```python
96
+ import swizzle
97
+ from dataclasses import dataclass
98
+
99
+ @swizzle
100
+ @dataclass
101
+ class Point:
102
+ x: int
103
+ y: int
104
+ z: int
105
+
106
+ p = Point(1, 2, 3)
107
+
108
+ print(p.zxy) # Output: Point(z=3, x=1, y=2)
109
+ ```
110
+
111
+ ### Swizzling Enums with `meta=True`
112
+
113
+ Enable attribute swizzling directly on the class by setting `meta=True`:
114
+
115
+ ```python
116
+ import swizzle
117
+ from enum import IntEnum
118
+
119
+ @swizzle(meta=True)
120
+ class Axis(IntEnum):
121
+ X = 1
122
+ Y = 2
123
+ Z = 3
124
+
125
+ print(Axis.YXZ) # Output: Axis(Y=<Axis.Y: 2>, X=<Axis.X: 1>, Z=<Axis.Z: 3>)
126
+ ```
127
+
128
+ ## Advanced Usage
129
+
130
+ ### Swizzled Named Tuples with `swizzledtuple`
131
+
132
+ Create swizzled named tuples inspired by `namedtuple`:
133
+
134
+ ```python
135
+ from swizzle import swizzledtuple
136
+
137
+ Vector = swizzledtuple('Vector', 'x y z')
138
+
139
+ v = Vector(1, 2, 3)
140
+
141
+ print(v.yzx) # Output: Vector(y=2, z=3, x=1)
142
+ print(v.yzx.xxzyzz) # Output: Vector(x=1, x=1, z=3, y=2, z=3, z=3)
143
+ ```
144
+
145
+ ### Custom Separators
146
+
147
+ Attributes are matched from left to right, starting with the longest substring match. This behavior can be controlled by the `sep` argument in the swizzle decorator:
148
+
149
+ ```python
150
+ import swizzle
151
+
152
+ @swizzle(meta=True, sep='_')
153
+ class BoundingBox:
154
+ x = 10
155
+ y = 20
156
+ w = 100
157
+ h = 200
158
+
159
+ print(BoundingBox.x_y_w_h) # Output: BoundingBox(x=10, y=20, w=100, h=200)
160
+ ```
161
+
162
+ ## Understanding Swizzling
163
+
164
+ Swizzling allows:
165
+
166
+ - **Rearrangement**: Access attributes in any order (e.g., `v.yzx`).
167
+ - **Duplication**: Access the same attribute multiple times (e.g., `v.xxy`).
168
+ - **Dynamic Composition**: Create new instances with desired attribute arrangements.
169
+
170
+ ## Benefits
171
+
172
+ - **Efficient Attribute Management**: Simplify complex attribute combinations.
173
+ - **Dynamic Access Patterns**: No need for predefined attribute combinations.
174
+ - **Cleaner Codebase**: Reduce redundancy and improve maintainability.
175
+ - **Enhanced Readability**: Code becomes more expressive and intuitive.
176
+
177
+ ## Conclusion
178
+
179
+ Swizzle is a powerful tool that streamlines attribute management in Python. It offers a flexible and efficient way to access and manipulate object attributes, making your code cleaner and more maintainable.
180
+
181
+ ## License
182
+
183
+ This project is licensed under the terms of the MIT license. See the [LICENSE](https://github.com/janthmueller/swizzle/blob/main/LICENSE) file for details.
184
+
185
+ ## Contributions
186
+
187
+ Contributions are welcome! Feel free to submit a Pull Request or open an Issue on GitHub.
188
+
189
+ ## Acknowledgments
190
+
191
+ Inspired by swizzling in graphics programming, Swizzle brings similar flexibility to Python attribute management.
192
+
193
+ ---
194
+
195
+ Give Swizzle a try and see how it can simplify your Python projects!
swizzle-2.2.0/PKG-INFO DELETED
@@ -1,128 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: swizzle
3
- Version: 2.2.0
4
- Summary: Swizzle enables the retrieval of multiple attributes, similar to swizzling in computer graphics.
5
- Home-page: https://github.com/janthmueller/swizzle
6
- Author: Jan T. Müller
7
- Author-email: mail@jantmueller.com
8
- License: MIT
9
- Project-URL: Documentation, https://github.com/janthmueller/swizzle/blob/main/README.md
10
- Project-URL: Source, https://github.com/janthmueller/swizzle
11
- Project-URL: Tracker, https://github.com/janthmueller/swizzle/issues
12
- Classifier: Intended Audience :: Developers
13
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
- Classifier: License :: OSI Approved :: MIT License
15
- Classifier: Operating System :: OS Independent
16
- Classifier: Programming Language :: Python :: 3 :: Only
17
- Requires-Python: >=3.6
18
- Description-Content-Type: text/markdown
19
- License-File: LICENSE
20
-
21
- # Swizzle
22
- [![PyPI Latest Release](https://img.shields.io/pypi/v/swizzle.svg)](https://pypi.org/project/swizzle/)
23
- [![Pepy Total Downlods](https://img.shields.io/pepy/dt/swizzle)](https://pepy.tech/project/swizzle)
24
- [![GitHub License](https://img.shields.io/github/license/janthmueller/swizzle)](https://github.com/janthmueller/swizzle/blob/main/LICENSE)
25
- [![GitHub Stars](https://img.shields.io/github/stars/janthmueller/swizzle.svg)](https://github.com/janthmueller/swizzle/stargazers)
26
-
27
- **Swizzle** for Python enhances attribute lookup methods to facilitate dynamic and flexible retrieval of multiple attributes based on specified arrangements of their names.
28
- > **Update v2:**
29
- > Introducing `swizzledtuple` , a new function that allows you to create swizzled named tuples. This feature is inspired by the `namedtuple` function from the [collections module](https://docs.python.org/3/library/collections.html#collections.namedtuple) and provides a concise way to define swizzled tuples.
30
- > ```python
31
- > from swizzle import swizzledtuple
32
- >
33
- > Vector = swizzledtuple('Vector', 'x y z', arrange_names = "y z x x")
34
- >
35
- > # Test the swizzle
36
- > v = Vector(1, 2, 3)
37
- > print(v) # Output: Vector(y=2, z=3, x=1, x=1)
38
- > print(v.yzx) # Output: Vector(y = 2, z = 3, x = 1)
39
- > print(v.yzx.xxzyzz) # Output: Vector(x=1, x=1, z=3, y=2, z=3, z=3)
40
- >```
41
-
42
- ### Swizzle Decorator:
43
-
44
- ```python
45
- import swizzle
46
-
47
- @swizzle
48
- class Vector:
49
- def __init__(self, x, y, z):
50
- self.x = x
51
- self.y = y
52
- self.z = z
53
-
54
- # Test the swizzle
55
- print(Vector(1, 2, 3).yzx) # Output: Vector(y = 2, z = 3, x = 1)
56
- ```
57
-
58
-
59
- ## Installation
60
- ### From PyPI
61
- ```bash
62
- pip install swizzle
63
- ```
64
- ### From GitHub
65
- ```bash
66
- pip install git+https://github.com/janthmueller/swizzle.git
67
- ```
68
-
69
- ## Further Examples
70
-
71
- ### Using `swizzle` with `dataclass`
72
-
73
- ```python
74
- import swizzle
75
- from dataclasses import dataclass
76
-
77
- @swizzle
78
- @dataclass
79
- class Vector:
80
- x: int
81
- y: int
82
- z: int
83
-
84
- # Test the swizzle
85
- print(Vector(1, 2, 3).yzx) # Output: Vector(y = 2, z = 3, x = 1)
86
- ```
87
-
88
- ### Using `swizzle` with `IntEnum`
89
-
90
- ```python
91
- import swizzle
92
- from enum import IntEnum
93
-
94
- @swizzle(meta=True)
95
- class Vector(IntEnum):
96
- X = 1
97
- Y = 2
98
- Z = 3
99
-
100
- # Test the swizzle
101
- print(Vector.YXZ) # Output: Vector(Y=<Vector.Y: 2>, X=<Vector.X: 1>, Z=<Vector.Z: 3>)
102
- ```
103
- Setting the `meta` argument to `True` in the swizzle decorator extends the `getattr` behavior of the metaclass, enabling attribute swizzling directly on the class itself.
104
-
105
-
106
- ### Sequential matching
107
- Attributes are matched from left to right, starting with the longest substring match. This behavior can be controlled by the `sep` argument in the swizzle decorator.
108
- ```python
109
- import swizzle
110
-
111
- @swizzle(meta=True)
112
- class Vector:
113
- x = 1
114
- y = 2
115
- z = 3
116
- xy = 4
117
- yz = 5
118
- xz = 6
119
- xyz = 7
120
-
121
- # Test the swizzle
122
- print(Vector.xz) # Output: 6
123
- print(Vector.yz) # Output: 5
124
- print(Vector.xyyz) # Output: Vector(xy=4, yz=5)
125
- print(Vector.xyzx) # Output: Vector(xyz=7, x=1)
126
- ```
127
-
128
-
swizzle-2.2.0/README.md DELETED
@@ -1,108 +0,0 @@
1
- # Swizzle
2
- [![PyPI Latest Release](https://img.shields.io/pypi/v/swizzle.svg)](https://pypi.org/project/swizzle/)
3
- [![Pepy Total Downlods](https://img.shields.io/pepy/dt/swizzle)](https://pepy.tech/project/swizzle)
4
- [![GitHub License](https://img.shields.io/github/license/janthmueller/swizzle)](https://github.com/janthmueller/swizzle/blob/main/LICENSE)
5
- [![GitHub Stars](https://img.shields.io/github/stars/janthmueller/swizzle.svg)](https://github.com/janthmueller/swizzle/stargazers)
6
-
7
- **Swizzle** for Python enhances attribute lookup methods to facilitate dynamic and flexible retrieval of multiple attributes based on specified arrangements of their names.
8
- > **Update v2:**
9
- > Introducing `swizzledtuple` , a new function that allows you to create swizzled named tuples. This feature is inspired by the `namedtuple` function from the [collections module](https://docs.python.org/3/library/collections.html#collections.namedtuple) and provides a concise way to define swizzled tuples.
10
- > ```python
11
- > from swizzle import swizzledtuple
12
- >
13
- > Vector = swizzledtuple('Vector', 'x y z', arrange_names = "y z x x")
14
- >
15
- > # Test the swizzle
16
- > v = Vector(1, 2, 3)
17
- > print(v) # Output: Vector(y=2, z=3, x=1, x=1)
18
- > print(v.yzx) # Output: Vector(y = 2, z = 3, x = 1)
19
- > print(v.yzx.xxzyzz) # Output: Vector(x=1, x=1, z=3, y=2, z=3, z=3)
20
- >```
21
-
22
- ### Swizzle Decorator:
23
-
24
- ```python
25
- import swizzle
26
-
27
- @swizzle
28
- class Vector:
29
- def __init__(self, x, y, z):
30
- self.x = x
31
- self.y = y
32
- self.z = z
33
-
34
- # Test the swizzle
35
- print(Vector(1, 2, 3).yzx) # Output: Vector(y = 2, z = 3, x = 1)
36
- ```
37
-
38
-
39
- ## Installation
40
- ### From PyPI
41
- ```bash
42
- pip install swizzle
43
- ```
44
- ### From GitHub
45
- ```bash
46
- pip install git+https://github.com/janthmueller/swizzle.git
47
- ```
48
-
49
- ## Further Examples
50
-
51
- ### Using `swizzle` with `dataclass`
52
-
53
- ```python
54
- import swizzle
55
- from dataclasses import dataclass
56
-
57
- @swizzle
58
- @dataclass
59
- class Vector:
60
- x: int
61
- y: int
62
- z: int
63
-
64
- # Test the swizzle
65
- print(Vector(1, 2, 3).yzx) # Output: Vector(y = 2, z = 3, x = 1)
66
- ```
67
-
68
- ### Using `swizzle` with `IntEnum`
69
-
70
- ```python
71
- import swizzle
72
- from enum import IntEnum
73
-
74
- @swizzle(meta=True)
75
- class Vector(IntEnum):
76
- X = 1
77
- Y = 2
78
- Z = 3
79
-
80
- # Test the swizzle
81
- print(Vector.YXZ) # Output: Vector(Y=<Vector.Y: 2>, X=<Vector.X: 1>, Z=<Vector.Z: 3>)
82
- ```
83
- Setting the `meta` argument to `True` in the swizzle decorator extends the `getattr` behavior of the metaclass, enabling attribute swizzling directly on the class itself.
84
-
85
-
86
- ### Sequential matching
87
- Attributes are matched from left to right, starting with the longest substring match. This behavior can be controlled by the `sep` argument in the swizzle decorator.
88
- ```python
89
- import swizzle
90
-
91
- @swizzle(meta=True)
92
- class Vector:
93
- x = 1
94
- y = 2
95
- z = 3
96
- xy = 4
97
- yz = 5
98
- xz = 6
99
- xyz = 7
100
-
101
- # Test the swizzle
102
- print(Vector.xz) # Output: 6
103
- print(Vector.yz) # Output: 5
104
- print(Vector.xyyz) # Output: Vector(xy=4, yz=5)
105
- print(Vector.xyzx) # Output: Vector(xyz=7, x=1)
106
- ```
107
-
108
-
@@ -1,128 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: swizzle
3
- Version: 2.2.0
4
- Summary: Swizzle enables the retrieval of multiple attributes, similar to swizzling in computer graphics.
5
- Home-page: https://github.com/janthmueller/swizzle
6
- Author: Jan T. Müller
7
- Author-email: mail@jantmueller.com
8
- License: MIT
9
- Project-URL: Documentation, https://github.com/janthmueller/swizzle/blob/main/README.md
10
- Project-URL: Source, https://github.com/janthmueller/swizzle
11
- Project-URL: Tracker, https://github.com/janthmueller/swizzle/issues
12
- Classifier: Intended Audience :: Developers
13
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
- Classifier: License :: OSI Approved :: MIT License
15
- Classifier: Operating System :: OS Independent
16
- Classifier: Programming Language :: Python :: 3 :: Only
17
- Requires-Python: >=3.6
18
- Description-Content-Type: text/markdown
19
- License-File: LICENSE
20
-
21
- # Swizzle
22
- [![PyPI Latest Release](https://img.shields.io/pypi/v/swizzle.svg)](https://pypi.org/project/swizzle/)
23
- [![Pepy Total Downlods](https://img.shields.io/pepy/dt/swizzle)](https://pepy.tech/project/swizzle)
24
- [![GitHub License](https://img.shields.io/github/license/janthmueller/swizzle)](https://github.com/janthmueller/swizzle/blob/main/LICENSE)
25
- [![GitHub Stars](https://img.shields.io/github/stars/janthmueller/swizzle.svg)](https://github.com/janthmueller/swizzle/stargazers)
26
-
27
- **Swizzle** for Python enhances attribute lookup methods to facilitate dynamic and flexible retrieval of multiple attributes based on specified arrangements of their names.
28
- > **Update v2:**
29
- > Introducing `swizzledtuple` , a new function that allows you to create swizzled named tuples. This feature is inspired by the `namedtuple` function from the [collections module](https://docs.python.org/3/library/collections.html#collections.namedtuple) and provides a concise way to define swizzled tuples.
30
- > ```python
31
- > from swizzle import swizzledtuple
32
- >
33
- > Vector = swizzledtuple('Vector', 'x y z', arrange_names = "y z x x")
34
- >
35
- > # Test the swizzle
36
- > v = Vector(1, 2, 3)
37
- > print(v) # Output: Vector(y=2, z=3, x=1, x=1)
38
- > print(v.yzx) # Output: Vector(y = 2, z = 3, x = 1)
39
- > print(v.yzx.xxzyzz) # Output: Vector(x=1, x=1, z=3, y=2, z=3, z=3)
40
- >```
41
-
42
- ### Swizzle Decorator:
43
-
44
- ```python
45
- import swizzle
46
-
47
- @swizzle
48
- class Vector:
49
- def __init__(self, x, y, z):
50
- self.x = x
51
- self.y = y
52
- self.z = z
53
-
54
- # Test the swizzle
55
- print(Vector(1, 2, 3).yzx) # Output: Vector(y = 2, z = 3, x = 1)
56
- ```
57
-
58
-
59
- ## Installation
60
- ### From PyPI
61
- ```bash
62
- pip install swizzle
63
- ```
64
- ### From GitHub
65
- ```bash
66
- pip install git+https://github.com/janthmueller/swizzle.git
67
- ```
68
-
69
- ## Further Examples
70
-
71
- ### Using `swizzle` with `dataclass`
72
-
73
- ```python
74
- import swizzle
75
- from dataclasses import dataclass
76
-
77
- @swizzle
78
- @dataclass
79
- class Vector:
80
- x: int
81
- y: int
82
- z: int
83
-
84
- # Test the swizzle
85
- print(Vector(1, 2, 3).yzx) # Output: Vector(y = 2, z = 3, x = 1)
86
- ```
87
-
88
- ### Using `swizzle` with `IntEnum`
89
-
90
- ```python
91
- import swizzle
92
- from enum import IntEnum
93
-
94
- @swizzle(meta=True)
95
- class Vector(IntEnum):
96
- X = 1
97
- Y = 2
98
- Z = 3
99
-
100
- # Test the swizzle
101
- print(Vector.YXZ) # Output: Vector(Y=<Vector.Y: 2>, X=<Vector.X: 1>, Z=<Vector.Z: 3>)
102
- ```
103
- Setting the `meta` argument to `True` in the swizzle decorator extends the `getattr` behavior of the metaclass, enabling attribute swizzling directly on the class itself.
104
-
105
-
106
- ### Sequential matching
107
- Attributes are matched from left to right, starting with the longest substring match. This behavior can be controlled by the `sep` argument in the swizzle decorator.
108
- ```python
109
- import swizzle
110
-
111
- @swizzle(meta=True)
112
- class Vector:
113
- x = 1
114
- y = 2
115
- z = 3
116
- xy = 4
117
- yz = 5
118
- xz = 6
119
- xyz = 7
120
-
121
- # Test the swizzle
122
- print(Vector.xz) # Output: 6
123
- print(Vector.yz) # Output: 5
124
- print(Vector.xyyz) # Output: Vector(xy=4, yz=5)
125
- print(Vector.xyzx) # Output: Vector(xyz=7, x=1)
126
- ```
127
-
128
-
File without changes
File without changes
File without changes