typing whitespace
This commit is contained in:
parent
2c52f9b561
commit
73c105d5cb
1 changed files with 7 additions and 4 deletions
|
|
@ -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.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue