mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-16 10:49:24 +00:00
Fix type hints for decorators in utils
This commit is contained in:
parent
73f953eac5
commit
61abb43b69
@ -120,6 +120,9 @@ class _cached_property:
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from functools import cached_property as cached_property
|
from functools import cached_property as cached_property
|
||||||
|
|
||||||
|
from typing_extensions import ParamSpec
|
||||||
|
|
||||||
from .permissions import Permissions
|
from .permissions import Permissions
|
||||||
from .abc import Snowflake
|
from .abc import Snowflake
|
||||||
from .invite import Invite
|
from .invite import Invite
|
||||||
@ -129,6 +132,8 @@ if TYPE_CHECKING:
|
|||||||
headers: Mapping[str, Any]
|
headers: Mapping[str, Any]
|
||||||
|
|
||||||
|
|
||||||
|
P = ParamSpec('P')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
cached_property = _cached_property
|
cached_property = _cached_property
|
||||||
|
|
||||||
@ -231,8 +236,8 @@ def parse_time(timestamp: Optional[str]) -> Optional[datetime.datetime]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def copy_doc(original: Callable[..., Any]) -> Callable[[Callable[..., Any]], Callable[..., Any]]:
|
def copy_doc(original: Callable[P, T]) -> Callable[[Callable[P, T]], Callable[P, T]]:
|
||||||
def decorator(overriden: Callable[..., Any]) -> Callable[..., Any]:
|
def decorator(overriden: Callable[P, T]) -> Callable[P, T]:
|
||||||
overriden.__doc__ = original.__doc__
|
overriden.__doc__ = original.__doc__
|
||||||
overriden.__signature__ = _signature(original) # type: ignore
|
overriden.__signature__ = _signature(original) # type: ignore
|
||||||
return overriden
|
return overriden
|
||||||
@ -240,10 +245,10 @@ def copy_doc(original: Callable[..., Any]) -> Callable[[Callable[..., Any]], Cal
|
|||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
def deprecated(instead: Optional[str] = None) -> Callable[[Callable[..., T]], Callable[..., T]]:
|
def deprecated(instead: Optional[str] = None) -> Callable[[Callable[P, T]], Callable[P, T]]:
|
||||||
def actual_decorator(func: Callable[..., T]) -> Callable[..., T]:
|
def actual_decorator(func: Callable[P, T]) -> Callable[P, T]:
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def decorated(*args, **kwargs) -> T:
|
def decorated(*args: P.args, **kwargs: P.kwargs) -> T:
|
||||||
warnings.simplefilter('always', DeprecationWarning) # turn off filter
|
warnings.simplefilter('always', DeprecationWarning) # turn off filter
|
||||||
if instead:
|
if instead:
|
||||||
fmt = "{0.__name__} is deprecated, use {1} instead."
|
fmt = "{0.__name__} is deprecated, use {1} instead."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user