From e5911754423e6f25e4f0200563ad9b6b0730fe85 Mon Sep 17 00:00:00 2001 From: Victor Skvortsov Date: Tue, 5 Mar 2024 18:32:40 +0500 Subject: [PATCH] Support Python 3.8 (#6) --- cached_classproperty/__init__.py | 10 +++++----- tests/test_classproperty.py | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cached_classproperty/__init__.py b/cached_classproperty/__init__.py index 509542b..7524116 100644 --- a/cached_classproperty/__init__.py +++ b/cached_classproperty/__init__.py @@ -1,6 +1,6 @@ import importlib.metadata from _thread import RLock # type: ignore -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Optional __version__ = importlib.metadata.version("cached_classproperty") @@ -17,12 +17,12 @@ P = ParamSpec("P") def cached_staticproperty( - func: Callable[Concatenate[P], T], attrname: str | None = None + func: Callable[Concatenate[P], T], attrname: Optional[str] = None ) -> T: ... def cached_classproperty( - func: Callable[Concatenate[Any, P], T], attrname: str | None = None + func: Callable[Concatenate[Any, P], T], attrname: Optional[str] = None ) -> T: ... @@ -31,7 +31,7 @@ def cached_classproperty( class cached_staticproperty: __slots__ = ("func", "attrname", "lock") - def __init__(self, func, attrname: str | None = None): + def __init__(self, func, attrname: Optional[str] = None): self.func = func self.attrname = attrname self.lock = RLock() @@ -72,7 +72,7 @@ def __get__(self, instance, owner=None): class cached_classproperty: __slots__ = ("func", "attrname", "lock", "owner", "_cached_value", "_weak_dict") - def __init__(self, func, attrname: str | None = None): + def __init__(self, func, attrname: Optional[str] = None): self.func = func self.attrname = attrname self.lock = RLock() diff --git a/tests/test_classproperty.py b/tests/test_classproperty.py index e4a149b..6156347 100644 --- a/tests/test_classproperty.py +++ b/tests/test_classproperty.py @@ -155,11 +155,11 @@ class Superclass: @cached_classproperty def my_cached_classproperty(cls): return ("Superclass",) + @classmethod def my_classmethod(cls): return ("Superclass",) - class Subclass1(Superclass): @cached_classproperty def my_cached_classproperty(cls): @@ -167,6 +167,7 @@ def my_cached_classproperty(cls): *super().my_cached_classproperty, "Subclass1", ) + @classmethod def my_classmethod(cls): return ( @@ -181,6 +182,7 @@ def my_cached_classproperty(cls): *super().my_cached_classproperty, "Subclass2", ) + @classmethod def my_classmethod(cls): return ( @@ -195,6 +197,7 @@ def my_cached_classproperty(cls): *super().my_cached_classproperty, "Finalclass", ) + @classmethod def my_classmethod(cls): return (