Skip to content

Commit

Permalink
Support Python 3.8 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
r4victor authored Mar 5, 2024
1 parent c20d46c commit e591175
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions cached_classproperty/__init__.py
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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:
...

Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion tests/test_classproperty.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,19 @@ 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):
return (
*super().my_cached_classproperty,
"Subclass1",
)

@classmethod
def my_classmethod(cls):
return (
Expand All @@ -181,6 +182,7 @@ def my_cached_classproperty(cls):
*super().my_cached_classproperty,
"Subclass2",
)

@classmethod
def my_classmethod(cls):
return (
Expand All @@ -195,6 +197,7 @@ def my_cached_classproperty(cls):
*super().my_cached_classproperty,
"Finalclass",
)

@classmethod
def my_classmethod(cls):
return (
Expand Down

0 comments on commit e591175

Please sign in to comment.