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.
@@ -46,7 +46,7 @@ def alias(*names: tuple[str], scope: object = None) -> Callable:
46
46
 
47
47
  thing = unwrap(thing)
48
48
 
49
- logger.info(f"@alias({names}) called on {thing}")
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 # (*args, **kwargs)
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 # (*args, **kwargs)
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
- if not scope:
98
- logger.warning(f"No module found for {thing.__module__}!")
99
-
100
- for module in sys.modules:
101
- logger.debug(f" => module => {module}")
102
-
103
- # The qualified name for module-level functions only contain the name of the
104
- # function, whereas functions nested within other functions or classes have
105
- # names comprised of multiple parts separated by the "." character; because
106
- # it is only currently possible to alias module-level functions, any nested
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
- return wrapper_function(*args, **kwargs)
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.info(f"Added alias '{name}' to {scope}.{thing}")
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 the alias!"
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.2
1
+ 1.0.3
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: classicist
3
- Version: 1.0.2
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 class methods;
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
- #### Class Method Alias Decorator & Metaclass: Add Aliases to Methods
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, and module-level functions, such that both the original name and any defined
270
- aliases can be used to access the same code object at runtime.
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 code object as one or more string arguments passed into 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 their aliases.
283
-
284
- The example below demonstrates adding an alias to a method defined within a class, and
285
- using the `aliased` metaclass when defining the class to ensure that the alias is parsed
286
- and translated to an additional class attribute so that the method is accessible via its
287
- original name and the alias at runtime.
288
-
289
- If control over the scope is required, the optional `scope` keyword argument can be
290
- used to specify the scope into which to apply the alias, this must be a reference to
291
- the globals() or locals() at the point in code where the `@alias()` decorator is used.
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=v-wuNFg62n5q8stzmT-3Wj9xR6bJQ-X_X1xClPxXe5A,5
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=e62ENmJh_kH4Ufh9duAYWg93cfmINIcpzeP0haJo7cw,7132
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.2.dist-info/licenses/LICENSE.md,sha256=qBmrjPmSCp0YFyaIl2G3FU3rniFD31YC0Yd3MrO1wEg,1070
22
- classicist-1.0.2.dist-info/METADATA,sha256=g3SDEBecgGq15CnHFUVr2mfyhFNQ3tG752I5OSMaAbk,24825
23
- classicist-1.0.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
24
- classicist-1.0.2.dist-info/top_level.txt,sha256=beG3ZuwObnmnY_mgNSN5CaVIWpI2VKszjVdKHPgZBhc,11
25
- classicist-1.0.2.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
26
- classicist-1.0.2.dist-info/RECORD,,
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,,