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 a Python version less than 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
Supported Type-Checkers
This package makes use of some reasonably advanced Python functionality, not supported by all static type checkers. While we will attempt to fix type bugs in this project for alternative type-checkers, our focus is on the following officially supported type checkersfootnote:[The list of officially supported type checkers is subject to change between any minor version release]:
- mypy
- tyfootnote:[Support for ty is provided for preview only until ty provides its first non-beta full release. Our support for ty may be revoked at any time, while it is still in preview.]
❗ IMPORTANT
Patches to fix bugs in this project for alternative type-checkers are welcome and much appreciated!
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.5.0.tar.gz.
File metadata
- Download URL: typed_classproperties-1.5.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5ff283e292616b6555bd0a853f7ac10ab532f887330c997c180f5733dca1215
|
|
| MD5 |
f35fdd867e720b355547967154c0578b
|
|
| BLAKE2b-256 |
e5236339ea6db274cf94d072aea65721a8ce5b085223cda4e3888c0df862e23f
|
File details
Details for the file typed_classproperties-1.5.0-py3-none-any.whl.
File metadata
- Download URL: typed_classproperties-1.5.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e5d65ae5f17658d82f181125e96f68eb3b68afb1b0d1955aa373e918bdb26e7
|
|
| MD5 |
a409af6fa97435167f797bb1624902a4
|
|
| BLAKE2b-256 |
8d3744050894a82595185c9ab018001d7f9698fc4478b8efc58bde547a055fbb
|