Typed decorators for classproperty and cached_classproperty.
Project description
typed_classproperties
Typed decorators for classproperty and cached_classproperty.
Python 3 compatible only*. No dependencies*footnote:[The library [typing_extensions](https://github.com/python/typing_extensions) is required when running with Python < 3.12].
Installation
This package is hosted on PyPI and can be installed using uv or pip.
Add to your uv project/script’s dependencies
uv add typed_classproperties
Install using pip after creating a virtual environment
path/to/venv/python -m 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 further usage examples and expected behaviour.
To run tests
uv run --group test -- pytest
Credits
Credits to Denis Ryzhkov, on Stack Overflow, for the original implementation of the @classproperty decorator:
https://stackoverflow.com/a/13624858/1280629
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 typed_classproperties-1.1.5.tar.gz.
File metadata
- Download URL: typed_classproperties-1.1.5.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
114ad8b2af4ad3d853d08ba57fba8229c3b17d2c3c2641a2d3361b2c066e9480
|
|
| MD5 |
a94a78efcc100cb61ab0266e0ace00ad
|
|
| BLAKE2b-256 |
732cae6a7094740f627e7742a11496a8f7991d02173858681f92d7313e519730
|
File details
Details for the file typed_classproperties-1.1.5-py3-none-any.whl.
File metadata
- Download URL: typed_classproperties-1.1.5-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4ba1bcd7530eb27f9986567771341203a613ca41ddde90aa2344fb3c6b76f18
|
|
| MD5 |
9f0735cb30d452e5dfd2cbf93e60227a
|
|
| BLAKE2b-256 |
e34e7b35d1fda85966a2291c02516ce1403eb41cb29afcab95d49301eefb1c44
|