classicist 1.0.2__py3-none-any.whl → 1.0.3__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.
- classicist/decorators/aliased/__init__.py +16 -22
- classicist/version.txt +1 -1
- {classicist-1.0.2.dist-info → classicist-1.0.3.dist-info}/METADATA +21 -18
- {classicist-1.0.2.dist-info → classicist-1.0.3.dist-info}/RECORD +8 -8
- {classicist-1.0.2.dist-info → classicist-1.0.3.dist-info}/WHEEL +0 -0
- {classicist-1.0.2.dist-info → classicist-1.0.3.dist-info}/licenses/LICENSE.md +0 -0
- {classicist-1.0.2.dist-info → classicist-1.0.3.dist-info}/top_level.txt +0 -0
- {classicist-1.0.2.dist-info → classicist-1.0.3.dist-info}/zip-safe +0 -0
|
@@ -46,7 +46,7 @@ def alias(*names: tuple[str], scope: object = None) -> Callable:
|
|
|
46
46
|
|
|
47
47
|
thing = unwrap(thing)
|
|
48
48
|
|
|
49
|
-
logger.
|
|
49
|
+
logger.debug(f"@alias({names}) called on {thing}")
|
|
50
50
|
|
|
51
51
|
if isinstance(aliases := getattr(thing, "_classicist_aliases", None), tuple):
|
|
52
52
|
setattr(thing, "_classicist_aliases", tuple([*aliases, *names]))
|
|
@@ -55,7 +55,7 @@ def alias(*names: tuple[str], scope: object = None) -> Callable:
|
|
|
55
55
|
|
|
56
56
|
@wraps(thing)
|
|
57
57
|
def wrapper_class(*args, **kwargs):
|
|
58
|
-
return thing
|
|
58
|
+
return thing
|
|
59
59
|
|
|
60
60
|
@wraps(thing)
|
|
61
61
|
def wrapper_method(*args, **kwargs):
|
|
@@ -63,7 +63,7 @@ def alias(*names: tuple[str], scope: object = None) -> Callable:
|
|
|
63
63
|
|
|
64
64
|
@wraps(thing)
|
|
65
65
|
def wrapper_function(*args, **kwargs):
|
|
66
|
-
return thing
|
|
66
|
+
return thing
|
|
67
67
|
|
|
68
68
|
if inspect.isclass(thing):
|
|
69
69
|
if not scope:
|
|
@@ -94,24 +94,18 @@ def alias(*names: tuple[str], scope: object = None) -> Callable:
|
|
|
94
94
|
if not scope:
|
|
95
95
|
scope = sys.modules.get(thing.__module__ or "__main__")
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
# or class methods are ignored during this stage of the aliasing process.
|
|
108
|
-
if len(thing.__qualname__.split(".")) > 1:
|
|
109
|
-
logger.warning(
|
|
110
|
-
"Unable to apply alias to functions defined beyond the top-level of a module: %s!"
|
|
111
|
-
% (thing.__qualname__)
|
|
112
|
-
)
|
|
97
|
+
# The qualified name for module-level functions only contain the name of the
|
|
98
|
+
# function, whereas functions nested within other functions or classes have
|
|
99
|
+
# names comprised of multiple parts separated by the "." character; because
|
|
100
|
+
# it is only currently possible to alias module-level functions, any nested
|
|
101
|
+
# or class methods are ignored during this stage of the aliasing process.
|
|
102
|
+
if len(thing.__qualname__.split(".")) > 1:
|
|
103
|
+
logger.debug(
|
|
104
|
+
"Unable to apply alias to functions defined beyond the top-level of a module: %s!"
|
|
105
|
+
% (thing.__qualname__)
|
|
106
|
+
)
|
|
113
107
|
|
|
114
|
-
|
|
108
|
+
return wrapper_function(*args, **kwargs)
|
|
115
109
|
|
|
116
110
|
# if signature := inspect.signature(thing):
|
|
117
111
|
# if len(parameters := signature.parameters) > 0 and "self" in parameters:
|
|
@@ -131,7 +125,7 @@ def alias(*names: tuple[str], scope: object = None) -> Callable:
|
|
|
131
125
|
)
|
|
132
126
|
)
|
|
133
127
|
|
|
134
|
-
logger.
|
|
128
|
+
logger.debug(f"Added alias '{name}' to {scope}.{thing}")
|
|
135
129
|
|
|
136
130
|
if isinstance(scope, dict):
|
|
137
131
|
scope[name] = thing
|
|
@@ -139,7 +133,7 @@ def alias(*names: tuple[str], scope: object = None) -> Callable:
|
|
|
139
133
|
setattr(scope, name, thing)
|
|
140
134
|
else:
|
|
141
135
|
logger.warning(
|
|
142
|
-
f"No scope was found or specified for {thing} into which to assign
|
|
136
|
+
f"No scope was found or specified for {thing} into which to assign aliases!"
|
|
143
137
|
)
|
|
144
138
|
|
|
145
139
|
return wrapper_function(*args, **kwargs)
|
classicist/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.0.
|
|
1
|
+
1.0.3
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: classicist
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Classy class decorators for Python.
|
|
5
5
|
Author: Daniel Sissman
|
|
6
6
|
License-Expression: MIT
|
|
@@ -39,7 +39,7 @@ The Classicist library provides several useful decorators and helper methods inc
|
|
|
39
39
|
* `@classproperty` – a decorator that allow class methods to be accessed as class properties;
|
|
40
40
|
* `@annotation` – a decorator that can be used to apply arbitrary annotations to code objects;
|
|
41
41
|
* `@deprecated` – a decorator that can be used to mark functions, classes and methods as being deprecated;
|
|
42
|
-
* `@alias` – a decorator that can be used to add aliases to
|
|
42
|
+
* `@alias` – a decorator that can be used to add aliases to classes, methods defined within classes, module-level functions, and nested functions when overriding the aliasing scope;
|
|
43
43
|
* `@nocache` – a decorator that can be used to mark functions and methods as not being suitable for caching;
|
|
44
44
|
* `shadowproof` – a metaclass that can be used to protect subclasses from class-level attributes
|
|
45
45
|
being overwritten (or shadowed) which can otherwise negatively affect class behaviour in some cases.
|
|
@@ -263,32 +263,35 @@ exampleclass.greeting = "goodbye"
|
|
|
263
263
|
assert exampleclass.greeting == "goodbye"
|
|
264
264
|
```
|
|
265
265
|
|
|
266
|
-
####
|
|
266
|
+
#### Alias Decorator & Metaclass: Add Aliases to Classes, Methods & Functions
|
|
267
267
|
|
|
268
268
|
The `@alias` decorator can be used to add aliases to classes, methods defined within
|
|
269
|
-
classes,
|
|
270
|
-
aliases can be used to access the same
|
|
269
|
+
classes, module-level functions, and nested functions when overriding the aliasing scope,
|
|
270
|
+
such that both the original name and any defined aliases can be used to access the same
|
|
271
|
+
code object at runtime.
|
|
271
272
|
|
|
272
273
|
To alias a class or a module-level function, that is a function defined at the top-level
|
|
273
274
|
of a module file (rather than nested within a function or class), simply decorate the
|
|
274
275
|
class or module-level function with the `@alias(...)` decorator and specify the one or
|
|
275
|
-
more name aliases for the
|
|
276
|
-
decorator method.
|
|
276
|
+
more name aliases for the class or function as one or more string arguments passed into
|
|
277
|
+
the decorator method.
|
|
277
278
|
|
|
278
279
|
To use the `@alias` decorator on methods defined within a class, it is also necessary to
|
|
279
280
|
set the containing class' metaclass to the `aliased` metaclass provided by the `classicist`
|
|
280
|
-
library; the metaclass iterates through the class namespace during parse time and sets up
|
|
281
|
+
library; the metaclass iterates through the class' namespace during parse time and sets up
|
|
281
282
|
the aliases as additional attributes on the class so that the aliased methods are available
|
|
282
|
-
at runtime via both their original name and
|
|
283
|
-
|
|
284
|
-
The
|
|
285
|
-
using the `aliased` metaclass when defining
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
283
|
+
at runtime via both their original name and any aliases.
|
|
284
|
+
|
|
285
|
+
The examples below demonstrate adding an alias to a module-level function, a class and a
|
|
286
|
+
method defined within a class, and using the `aliased` metaclass when defining a class
|
|
287
|
+
that contains aliased methods to ensure that any aliases are parsed and translated to
|
|
288
|
+
additional class attributes so that the method is accessible via its original name and
|
|
289
|
+
any alias at runtime.
|
|
290
|
+
|
|
291
|
+
If control over the scope is required, usually for nested functions, the optional `scope`
|
|
292
|
+
keyword-only argument can be used to specify the scope into which to apply the alias; this
|
|
293
|
+
must be a reference to `globals()` or `locals()` at the point in code where the `@alias(...)`
|
|
294
|
+
decorator is applied to the nested function.
|
|
292
295
|
|
|
293
296
|
```python
|
|
294
297
|
from classicist import aliased, alias, is_aliased, aliases
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
classicist/__init__.py,sha256=Rkm1Vx0Z-BHPH1FSzFLrAxwkFEt1xvMxZz-mC8FJSDc,834
|
|
2
|
-
classicist/version.txt,sha256=
|
|
2
|
+
classicist/version.txt,sha256=INLLCW0atBpBQCRtEvB79rjLdD_UgSK3JTLAPUTFwUo,5
|
|
3
3
|
classicist/decorators/__init__.py,sha256=wplcs2JnyGMOh72626-x-WyVotVoT7nvk-dpjeTXQ88,600
|
|
4
|
-
classicist/decorators/aliased/__init__.py,sha256=
|
|
4
|
+
classicist/decorators/aliased/__init__.py,sha256=vW1P9jbGkOD_m9GvgEXF0Uni-Dt6rfVXDVF5D4wC1GY,6926
|
|
5
5
|
classicist/decorators/annotation/__init__.py,sha256=20WwmrXDxT85sItpDiCdC-hZjbyDR6E2mLPMSKQgm8g,1796
|
|
6
6
|
classicist/decorators/classproperty/__init__.py,sha256=ED37_20UeAGKX1ahsv16wTg0JAJT4UBLqiNRbKAp2KE,1646
|
|
7
7
|
classicist/decorators/deprecated/__init__.py,sha256=aAPFQoT-pJf1nauQGiPADkPBREMvEQJaUQc3kjA48Rg,2764
|
|
@@ -18,9 +18,9 @@ classicist/logging/__init__.py,sha256=LJ-Nih1LacPrO2TvTT6l84So-pgw84AHJ8IhzYKl5r
|
|
|
18
18
|
classicist/metaclasses/__init__.py,sha256=mYhR5rM7cnJlaNUlgoQWOo44RQSORteRjYd0y0BajxQ,159
|
|
19
19
|
classicist/metaclasses/aliased/__init__.py,sha256=grs4Z8dMY6R2fCFn4UCPdCzEJtVaAv-tsWFwY1DCUpI,2033
|
|
20
20
|
classicist/metaclasses/shadowproof/__init__.py,sha256=d55uNjcaCorD3MdDUv7aRVpk2MlE8JzMjint6Vvf_Yc,1492
|
|
21
|
-
classicist-1.0.
|
|
22
|
-
classicist-1.0.
|
|
23
|
-
classicist-1.0.
|
|
24
|
-
classicist-1.0.
|
|
25
|
-
classicist-1.0.
|
|
26
|
-
classicist-1.0.
|
|
21
|
+
classicist-1.0.3.dist-info/licenses/LICENSE.md,sha256=qBmrjPmSCp0YFyaIl2G3FU3rniFD31YC0Yd3MrO1wEg,1070
|
|
22
|
+
classicist-1.0.3.dist-info/METADATA,sha256=iZaQqjD9wd84Bb_Dx_Se-RMYgZTvvf2Hkf2idrnswgk,25128
|
|
23
|
+
classicist-1.0.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
24
|
+
classicist-1.0.3.dist-info/top_level.txt,sha256=beG3ZuwObnmnY_mgNSN5CaVIWpI2VKszjVdKHPgZBhc,11
|
|
25
|
+
classicist-1.0.3.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
26
|
+
classicist-1.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|