Typed decorators for classproperty and cached_classproperty.
Project description
typed_classproperties
Typed decorators for classproperty and cached_classproperty.
Python 3 compatible only. No dependencies.
Installation
This package is hosted on PYPI and can be installed using uv
or pip
. E.g.
uv add typed_classproperties
pip install typed_classproperties
Example usage
from typing import override
from typed_classproperties import classproperty, cached_classproperty
class Foo:
@override
def __init__(self, bar: str) -> None:
self.bar: str = bar
@classproperty
def BAR(cls) -> int:
return 1
assert Foo.BAR == 1
assert Foo(bar="one").BAR == 1
class CachedFoo:
@override
def __init__(self, bar: str) -> None:
self.bar: str = bar
@cached_classproperty
def BAR(cls) -> int:
print("This will be executed only once")
return 1
assert CachedFoo.BAR == 1
assert CachedFoo(bar="bar").FOO == 1
Tests
See tests.py
for usage examples and expected behaviour.
To run tests:
uv run --group test pytest
Credits
Credits to Denis Ryzhkov on Stackoverflow for the implementation of classproperty: https://stackoverflow.com/a/13624858/1280629
Project details
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
File details
Details for the file typed_classproperties-0.2.5.tar.gz
.
File metadata
- Download URL: typed_classproperties-0.2.5.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.4.29
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21534dcc025118b26e715db0d2963c87716ea6117ea132c0cf391074d7d06b0e |
|
MD5 | d649ba34cbedd1d0caa20cd1c882b945 |
|
BLAKE2b-256 | 63d93b9c1aa6d01871133ca968bf442e08257bfec9c7b880eaef3d0e221e9454 |
File details
Details for the file typed_classproperties-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: typed_classproperties-0.2.5-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.4.29
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bfaa0192d4b181cb8e6f8346e0fe9430b940e84b7fb49be8b29a79d98bb2eaa |
|
MD5 | 93e41ead0255e3ef527b39a331f1a04c |
|
BLAKE2b-256 | d431928bb615d94bfce6b51f0b45dcaed0e7ab8e36331e13cc330b9f2fc16c78 |