diff --git a/pyproject.toml b/pyproject.toml index fa74005..b8923fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,7 @@ classifiers = [ "Topic :: Software Development", "Typing :: Typed", ] +dependencies = ["typing-extensions; python_version < '3.12'"] dynamic = ["description", "version"] keywords = ["classmethod", "decorator", "property"] license = "MIT" diff --git a/tests.py b/tests.py index 3f8d52e..effaf61 100644 --- a/tests.py +++ b/tests.py @@ -1,8 +1,14 @@ """Full test suite for 'typed_classproperties' library.""" import abc +import sys from typing import TYPE_CHECKING, Any +if sys.version_info >= (3, 12): + from typing import override +else: + from typing_extensions import override + from typed_classproperties import cached_classproperty, classproperty if TYPE_CHECKING: @@ -53,6 +59,7 @@ def base_method(cls) -> str: class _SubClass(_BaseClass): @classproperty + @override def base_method(cls) -> str: return "" diff --git a/typed_classproperties/__init__.py b/typed_classproperties/__init__.py index 702d16d..565c670 100644 --- a/typed_classproperties/__init__.py +++ b/typed_classproperties/__init__.py @@ -10,6 +10,11 @@ overload, ) +if sys.version_info >= (3, 12): + from typing import override +else: + from typing_extensions import override + if TYPE_CHECKING: from collections.abc import Callable, Sequence from typing import Final @@ -30,10 +35,12 @@ class classproperty(property, Generic[T_class, T_value]): Credit to Denis Rhyzhkov on Stackoverflow: https://stackoverflow.com/a/13624858/1280629 """ + @override def __init__(self, func: "Callable[..., T_value]", /) -> None: """Initialise the classproperty object.""" super().__init__(func) + @override def __get__(self, owner_self: object, owner_cls: "type | None" = None, /) -> T_value: """Retrieve the value of the property.""" if self.fget is None: @@ -66,6 +73,7 @@ class cached_classproperty( as this will completely remove the cached value and the cached property setter. """ + @override def __set_name__(self, owner: type, name: str, /) -> None: """Store the lookupkeyof the cached-classproperty.""" super().__set_name__(owner, name) @@ -95,11 +103,14 @@ def _get_cached_property(self, owner: "type[Any] | None") -> Any: # noqa: ANN40 return val @overload + @override def __get__(self, instance: None, owner: "type[Any] | None" = None, /) -> "Self": ... @overload + @override def __get__(self, instance: object, owner: "type[Any] | None" = None, /) -> T_value: ... + @override def __get__( self, instance: object, owner: "type[Any] | None" = None, / ) -> "Self | T_value": diff --git a/uv.lock b/uv.lock index 19c3bde..326959e 100644 --- a/uv.lock +++ b/uv.lock @@ -306,6 +306,9 @@ wheels = [ [[package]] name = "typed-classproperties" source = { editable = "." } +dependencies = [ + { name = "typing-extensions", marker = "python_full_version < '3.12'" }, +] [package.dev-dependencies] dev = [ @@ -328,6 +331,7 @@ type-check = [ ] [package.metadata] +requires-dist = [{ name = "typing-extensions", marker = "python_full_version < '3.12'" }] [package.metadata.requires-dev] dev = [