Skip to main content

Typed decorators for classproperty and cached_classproperty.

Project description

typed_classproperties

Pydowndoc PyPI Version Python Version Tests Status mypy Status Ruff uv

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.

Add to your uv project/script’s dependencies

uv add typed_classproperties

Install using pip

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 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

typed_classproperties-1.1.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typed_classproperties-1.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file typed_classproperties-1.1.1.tar.gz.

File metadata

File hashes

Hashes for typed_classproperties-1.1.1.tar.gz
Algorithm Hash digest
SHA256 da4de2e191872fef2caefdd8c65b848ac778b4f1af517f16af1111c7bb194c01
MD5 9642547118e790802dbbdab6739e225a
BLAKE2b-256 dcf8eca09b814d5111dfed1a83da49766a3bf4abfdba8e9bcbfd427eda08c092

See more details on using hashes here.

File details

Details for the file typed_classproperties-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for typed_classproperties-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 44eb5e9384c9c92ae9cb1068e86f322c15c7c96a13f444aaf9dc784b88d5622b
MD5 a11752045e48302e2e624a2e585525bb
BLAKE2b-256 3ae12bb1405dd50424d4beebb3bc1c0cdc07cfe573d8b704150fd0360274fab1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page