From 66e555c63c22668cd342fbe5cd4f561417938b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AB=B9=E6=B0=B8=E5=BA=B7?= Date: Thu, 10 Oct 2024 09:11:48 +0800 Subject: [PATCH] 2.0.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.Fix a critical error. 2.Improve a few type annotations. 1.修复一个严重的错误。 2.改进少量类型注解。 --- funccache/__init__.py | 2 +- funccache/i funccache.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/funccache/__init__.py b/funccache/__init__.py index 8792488..f485d86 100644 --- a/funccache/__init__.py +++ b/funccache/__init__.py @@ -14,7 +14,7 @@ ──────────────────────────────────────────────────────────────────────────────── Copyright (c) 2022-2024 GQYLPY . All rights reserved. - @version: 2.0.3 + @version: 2.0.4 @author: 竹永康 @source: https://github.com/gqylpy/funccache diff --git a/funccache/i funccache.py b/funccache/i funccache.py index 0d1c898..4e4fb32 100644 --- a/funccache/i funccache.py +++ b/funccache/i funccache.py @@ -33,6 +33,7 @@ TypeAlias = TypeVar("TypeAlias") MethodTypeOrName: TypeAlias = TypeVar('MethodTypeOrName', MethodType, str) +TTL: TypeAlias = TypeVar('TTL', int, float, str) Wrapped = WrappedClosure = TypeVar('Wrapped', bound=Callable[..., Any]) WrappedReturn: TypeAlias = TypeVar('WrappedReturn') @@ -50,7 +51,7 @@ class FuncCache(type): __shared_instance_cache__: bool = False __not_cache__: List[MethodTypeOrName] = [] - __ttl__: Union[str, int, float] = float('inf') + __ttl__: TTL = float('inf') def __new__( mcs, __name__: Union[str, Wrapped, Type[object]], *a, **kw @@ -67,7 +68,7 @@ def __init__(cls, __name__: str, __bases__: tuple, __dict__: dict): cls.check_and_tidy_not_cache(__not_cache__) cls.dedup(__not_cache__) - if '__getattribute__' not in __dict__: + if '__getattribute__' in __dict__: raise AttributeError( f'instances of "{FuncCache.__name__}" are not allowed to ' 'define method "__getattribute__".' @@ -316,7 +317,7 @@ async def acore(self, *a, **kw) -> WrappedReturn: class FunctionCallerTTL: - def __init__(self, ttl: Union[int, float, str] = float('inf'), /): + def __init__(self, ttl: TTL = float('inf'), /): if isinstance(ttl, str): ttl = time2second(ttl) elif not isinstance(ttl, (int, float)):