Skip to content

Commit

Permalink
Fix stricter mypy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
CarrotManMatt committed Jan 31, 2025
1 parent 5dac567 commit 24ca3b4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -53,6 +59,7 @@ def base_method(cls) -> str:

class _SubClass(_BaseClass):
@classproperty
@override
def base_method(cls) -> str:
return ""

Expand Down
11 changes: 11 additions & 0 deletions typed_classproperties/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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":
Expand Down
4 changes: 4 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24ca3b4

Please sign in to comment.