typed_classproperties
Typed decorators for
classpropertyandcached_classproperty.Python 3 compatible only. No dependenciesfootnote:[The library
[typing_extensions](https://github.com/python/typing_extensions)is required when running with a Python version less than3.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 that could be considered a hack. The appropriate solution to correctly annotate the types matching the runtime behaviour of classproperties is explained in PEP767. This PEP, however, is still in draft and not yet accepted; therefore, not all type checkers are supported.
While we will attempt to fix type annotation 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
- ty ≤ 0.0.59footnote:[Support for ty is capped to below 0.0.60, which began to find type-errors with the hacks used in this project]
❗ 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
Metadata
Release files for typed_classproperties 1.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| typed_classproperties-1.6.0.tar.gz | 12.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| typed_classproperties-1.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.9 kB
Release files / typed_classproperties-1.6.0.tar.gz
| Download URL | typed_classproperties-1.6.0.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7355dffcfc56e51661f60dff9d635418dde09941a1c14ff3592f0bb59529109
|
|
BLAKE2b-256 checksum How to use checksums |
4290fc685adbaf4f3368af5032b68f13100a7faa6dc3eba6daf1db8f679776c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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}
|
Release files / typed_classproperties-1.6.0-py3-none-any.whl
| Download URL | typed_classproperties-1.6.0-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2354a32df75ac6fe7355626dccca4de5c729d6b03e789759fcbb395e4c175daf
|
|
BLAKE2b-256 checksum How to use checksums |
5ede05cd10952b95464f556fcdc4a1302366fdd105b973ef7ca65bfe85314a7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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}
|