# typed_classproperties
![Pydowndoc](https://img.shields.io/badge/%F0%9F%A5%95-typed__classproperties-blue)
![PyPI Version](https://img.shields.io/pypi/v/typed_classproperties)
![Python Version](https://img.shields.io/pypi/pyversions/typed_classproperties?logo=Python&logoColor=white&label=Python)
![Tests Status](https://github.com/CarrotManMatt/typed_classproperties/actions/workflows/check-build-publish.yaml/badge.svg)
![mypy Status](https://img.shields.io/badge/mypy-checked-%232EBB4E&label=mypy)
![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)
![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)
Typed decorators for `classproperty` and `cached_classproperty`.
***Python 3 compatible only****. **No dependencies***.
## Installation
This package is hosted on [PyPI](https://pypi.org) and can be installed using
[uv](https://astral.sh/uv) or [pip](https://pip.pypa.io).
**Add to your [uv project/script’s dependencies](https://docs.astral.sh/uv/concepts/projects#managing-dependencies)**
uv add typed_classproperties
**Install using [pip](https://pip.pypa.io)**
path/to/venv/python -m pip install typed_classproperties
## Example Usage
```python
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](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
Raw data
{
"_id": null,
"home_page": null,
"name": "typed_classproperties",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "Matt Norton <matt@carrotmanmatt.com>",
"keywords": "classmethod, decorator, property",
"author": null,
"author_email": "Jonathan Clarke <jonathan.a.clarke@gmail.com>, Matt Norton <matt@carrotmanmatt.com>",
"download_url": "https://files.pythonhosted.org/packages/9f/80/fd262e0b6a7c0ffd1f9ed60c3a351a766a399d79f4d6805bd8543c7fb855/typed_classproperties-1.1.3.tar.gz",
"platform": null,
"description": "# typed_classproperties\n\n![Pydowndoc](https://img.shields.io/badge/%F0%9F%A5%95-typed__classproperties-blue)\n![PyPI Version](https://img.shields.io/pypi/v/typed_classproperties)\n![Python Version](https://img.shields.io/pypi/pyversions/typed_classproperties?logo=Python&logoColor=white&label=Python)\n![Tests Status](https://github.com/CarrotManMatt/typed_classproperties/actions/workflows/check-build-publish.yaml/badge.svg)\n![mypy Status](https://img.shields.io/badge/mypy-checked-%232EBB4E&label=mypy)\n![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)\n![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)\n\nTyped decorators for `classproperty` and `cached_classproperty`.\n\n***Python 3 compatible only****. **No dependencies***.\n\n## Installation\n\nThis package is hosted on [PyPI](https://pypi.org) and can be installed using\n[uv](https://astral.sh/uv) or [pip](https://pip.pypa.io).\n\n**Add to your [uv project/script\u2019s dependencies](https://docs.astral.sh/uv/concepts/projects#managing-dependencies)**\n\nuv add typed_classproperties\n\n**Install using [pip](https://pip.pypa.io)**\n\npath/to/venv/python -m pip install typed_classproperties\n\n## Example Usage\n\n```python\nfrom typing import override\n\nfrom typed_classproperties import classproperty, cached_classproperty\n\n\nclass Foo:\n @override\n def __init__(self, bar: str) -> None:\n self.bar: str = bar\n\n @classproperty\n def BAR(cls) -> int:\n return 1\n\n\nassert Foo.BAR == 1\nassert Foo(bar=\"one\").BAR == 1\n\n\nclass CachedFoo:\n @override\n def __init__(self, bar: str) -> None:\n self.bar: str = bar\n\n @cached_classproperty\n def BAR(cls) -> int:\n print(\"This will be executed only once\")\n return 1\n\n\nassert CachedFoo.BAR == 1\nassert CachedFoo(bar=\"bar\").FOO == 1\n```\n\n## Tests\n\nSee [tests.py](tests.py) for usage examples and expected behaviour.\n\n**To run tests**\n\nuv run --group test -- pytest\n\n## Credits\n\nCredits to Denis Ryzhkov on Stackoverflow for the implementation of classproperty:\nhttps://stackoverflow.com/a/13624858/1280629\n",
"bugtrack_url": null,
"license": null,
"summary": "Typed decorators for classproperty and cached_classproperty.",
"version": "1.1.3",
"project_urls": {
"Issues": "https://github.com/CarrotManMatt/typed_classproperties/issues",
"Repository": "https://github.com/CarrotManMatt/typed_classproperties"
},
"split_keywords": [
"classmethod",
" decorator",
" property"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "3cbbe1dcd2e080362e2dc026364a478a4fa539316c5be660ece320f15e874d8e",
"md5": "eb280f93fc9071c657347d6b66ed4116",
"sha256": "05b9f43ed01b8c06b250f508fd8c29136e26309751a7d7f2060ae487bbf1f241"
},
"downloads": -1,
"filename": "typed_classproperties-1.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "eb280f93fc9071c657347d6b66ed4116",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 5032,
"upload_time": "2025-01-01T16:51:45",
"upload_time_iso_8601": "2025-01-01T16:51:45.591967Z",
"url": "https://files.pythonhosted.org/packages/3c/bb/e1dcd2e080362e2dc026364a478a4fa539316c5be660ece320f15e874d8e/typed_classproperties-1.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "9f80fd262e0b6a7c0ffd1f9ed60c3a351a766a399d79f4d6805bd8543c7fb855",
"md5": "92b4a511604ca2abca8b27a9c3b0bec7",
"sha256": "c0b99d160da6c63e2d321db22903cf88cbc6c50bb00fc14f9ee3bb525e706459"
},
"downloads": -1,
"filename": "typed_classproperties-1.1.3.tar.gz",
"has_sig": false,
"md5_digest": "92b4a511604ca2abca8b27a9c3b0bec7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 6261,
"upload_time": "2025-01-01T16:51:46",
"upload_time_iso_8601": "2025-01-01T16:51:46.597837Z",
"url": "https://files.pythonhosted.org/packages/9f/80/fd262e0b6a7c0ffd1f9ed60c3a351a766a399d79f4d6805bd8543c7fb855/typed_classproperties-1.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-01 16:51:46",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "CarrotManMatt",
"github_project": "typed_classproperties",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "typed_classproperties"
}