typing whitespace

This commit is contained in:
Yusur 2025-07-30 23:00:46 +02:00
parent 2c52f9b561
commit 73c105d5cb

View file

@ -16,21 +16,24 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import math import math
import time import time
from typing import Callable from typing import Callable, TypeVar
import warnings import warnings
from functools import wraps, lru_cache from functools import wraps, lru_cache
_T = TypeVar('_T')
_U = TypeVar('_U')
try: try:
from warnings import deprecated from warnings import deprecated
except ImportError: except ImportError:
# Python <=3.12 does not implement warnings.deprecated # Python <=3.12 does not implement warnings.deprecated
def deprecated(message: str, /, *, category=DeprecationWarning, stacklevel: int = 1): def deprecated(message: str, /, *, category=DeprecationWarning, stacklevel: int = 1) -> Callable[[Callable[_T, _U]], Callable[_T, _U]]:
""" """
Backport of PEP 702 for Python <=3.12. Backport of PEP 702 for Python <=3.12.
The stack_level stuff is not reimplemented on purpose because The stack_level stuff is not reimplemented on purpose because
too obscure for the average programmer. too obscure for the average programmer.
""" """
def decorator(func: Callable) -> Callable: def decorator(func: Callable[_T, _U]) -> Callable[_T, _U]:
@wraps(func) @wraps(func)
def wrapper(*a, **ka): def wrapper(*a, **ka):
if category is not None: if category is not None:
@ -89,7 +92,7 @@ def timed_cache(ttl: int, maxsize: int = 128, typed: bool = False) -> Callable[[
return wrapper return wrapper
return decorator return decorator
def none_pass(func: Callable, *args, **kwargs): def none_pass(func: Callable, *args, **kwargs) -> Callable:
""" """
Wrap callable so that gets called only on not None values. Wrap callable so that gets called only on not None values.