No project description provided
Project description
Classmethod Decorators
A small Python hack that allows using a @classmethod within the same class as a decorator for other methods in the same class, which is not typically possible because functions are turned into methods once the class definition is complete.
Installation
pip install classmethod_decorators
Usage
from typing import Callable
from typing_extensions import Self
from classmethod_decorators import enable_classmethod_decorators, classmethod_decorator
@enable_classmethod_decorators
class Foo:
@classmethod
def register(cls, method: Callable[[Self], None]) -> Callable[[Self], None]:
print(f"{method} is registered")
def decorated(self: Self) -> None:
print(f"decorated {method}")
method(self)
return decorated
@classmethod_decorator(register)
def method(self) -> None:
print("method")
Foo().method()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file classmethod_decorator-0.2.0.tar.gz.
File metadata
- Download URL: classmethod_decorator-0.2.0.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/5.15.153.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dbb6ee73e9f2f8e43f9df46882a2648f9711eb26b587a74e662457cd52b8fc7
|
|
| MD5 |
4f35a819a0302a96a9df2e0424cde107
|
|
| BLAKE2b-256 |
172d1dc19ee59be3492ee22fd5ac77d2375ebed94d555c938455e65ba46b19f7
|
File details
Details for the file classmethod_decorator-0.2.0-py3-none-any.whl.
File metadata
- Download URL: classmethod_decorator-0.2.0-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/5.15.153.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5575568c9b93a5ba3827e2ae9e32911f403ae56912818b4759165e4136fde35a
|
|
| MD5 |
e09043100c0095bb946751d011c541b7
|
|
| BLAKE2b-256 |
812c01a4162a0df961e2b33db75d6a86e8d31a55786f7c7d0e1c45c067da4ede
|