Fix typehints and add more emoji

This commit is contained in:
Alex Root Junior 2021-01-24 21:51:25 +02:00
parent 281dda52de
commit 04ce94183c
5 changed files with 148 additions and 88 deletions

View file

@ -19,3 +19,6 @@ class Dice(TelegramObject):
class DiceEmoji:
DICE = "🎲"
DART = "🎯"
BASKETBALL = "🏀"
FOOTBALL = ""
SLOT_MACHINE = "🎰"

View file

@ -2,10 +2,10 @@ import asyncio
import functools
import inspect
import warnings
from typing import Callable
from typing import Any, Callable, Type
def deprecated(reason, stacklevel=2) -> Callable:
def deprecated(reason: str, stacklevel: int = 2) -> Callable[..., Any]:
"""
This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
@ -24,7 +24,7 @@ def deprecated(reason, stacklevel=2) -> Callable:
# def old_function(x, y):
# pass
def decorator(func):
def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
if inspect.isclass(func):
msg = "Call to deprecated class {name} ({reason})."
@ -32,7 +32,7 @@ def deprecated(reason, stacklevel=2) -> Callable:
msg = "Call to deprecated function {name} ({reason})."
@functools.wraps(func)
def wrapper(*args, **kwargs):
def wrapper(*args: Any, **kwargs: Any) -> Any:
warn_deprecated(
msg.format(name=func.__name__, reason=reason), stacklevel=stacklevel
)
@ -70,13 +70,17 @@ def deprecated(reason, stacklevel=2) -> Callable:
raise TypeError(repr(type(reason)))
def warn_deprecated(message, warning=DeprecationWarning, stacklevel=2):
def warn_deprecated(
message: str, warning: Type[Warning] = DeprecationWarning, stacklevel: int = 2
) -> None:
warnings.simplefilter("always", warning)
warnings.warn(message, category=warning, stacklevel=stacklevel)
warnings.simplefilter("default", warning)
def renamed_argument(old_name: str, new_name: str, until_version: str, stacklevel: int = 3):
def renamed_argument(
old_name: str, new_name: str, until_version: str, stacklevel: int = 3
) -> Callable[..., Any]:
"""
A meta-decorator to mark an argument as deprecated.
@ -100,11 +104,11 @@ def renamed_argument(old_name: str, new_name: str, until_version: str, stackleve
:return: decorator
"""
def decorator(func):
def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
if asyncio.iscoroutinefunction(func):
@functools.wraps(func)
async def wrapped(*args, **kwargs):
async def wrapped(*args: Any, **kwargs: Any) -> Any:
if old_name in kwargs:
warn_deprecated(
f"In coroutine '{func.__name__}' argument '{old_name}' "
@ -119,7 +123,7 @@ def renamed_argument(old_name: str, new_name: str, until_version: str, stackleve
else:
@functools.wraps(func)
def wrapped(*args, **kwargs):
def wrapped(*args: Any, **kwargs: Any) -> Any:
if old_name in kwargs:
warn_deprecated(
f"In function `{func.__name__}` argument `{old_name}` "

View file

@ -1,11 +1,13 @@
from typing import Any
from .text_decorations import html_decoration, markdown_decoration
def _join(*content, sep=" "):
def _join(*content: Any, sep: str = " ") -> str:
return sep.join(map(str, content))
def text(*content, sep=" "):
def text(*content: Any, sep: str = " ") -> str:
"""
Join all elements with a separator
@ -16,7 +18,7 @@ def text(*content, sep=" "):
return _join(*content, sep=sep)
def bold(*content, sep=" "):
def bold(*content: Any, sep: str = " ") -> str:
"""
Make bold text (Markdown)
@ -27,7 +29,7 @@ def bold(*content, sep=" "):
return markdown_decoration.bold(value=html_decoration.quote(_join(*content, sep=sep)))
def hbold(*content, sep=" "):
def hbold(*content: Any, sep: str = " ") -> str:
"""
Make bold text (HTML)
@ -38,7 +40,7 @@ def hbold(*content, sep=" "):
return html_decoration.bold(value=html_decoration.quote(_join(*content, sep=sep)))
def italic(*content, sep=" "):
def italic(*content: Any, sep: str = " ") -> str:
"""
Make italic text (Markdown)
@ -49,7 +51,7 @@ def italic(*content, sep=" "):
return markdown_decoration.italic(value=html_decoration.quote(_join(*content, sep=sep)))
def hitalic(*content, sep=" "):
def hitalic(*content: Any, sep: str = " ") -> str:
"""
Make italic text (HTML)
@ -60,7 +62,7 @@ def hitalic(*content, sep=" "):
return html_decoration.italic(value=html_decoration.quote(_join(*content, sep=sep)))
def code(*content, sep=" "):
def code(*content: Any, sep: str = " ") -> str:
"""
Make mono-width text (Markdown)
@ -71,7 +73,7 @@ def code(*content, sep=" "):
return markdown_decoration.code(value=html_decoration.quote(_join(*content, sep=sep)))
def hcode(*content, sep=" "):
def hcode(*content: Any, sep: str = " ") -> str:
"""
Make mono-width text (HTML)
@ -82,7 +84,7 @@ def hcode(*content, sep=" "):
return html_decoration.code(value=html_decoration.quote(_join(*content, sep=sep)))
def pre(*content, sep="\n"):
def pre(*content: Any, sep: str = "\n") -> str:
"""
Make mono-width text block (Markdown)
@ -93,7 +95,7 @@ def pre(*content, sep="\n"):
return markdown_decoration.pre(value=html_decoration.quote(_join(*content, sep=sep)))
def hpre(*content, sep="\n"):
def hpre(*content: Any, sep: str = "\n") -> str:
"""
Make mono-width text block (HTML)
@ -104,7 +106,7 @@ def hpre(*content, sep="\n"):
return html_decoration.pre(value=html_decoration.quote(_join(*content, sep=sep)))
def underline(*content, sep=" "):
def underline(*content: Any, sep: str = " ") -> str:
"""
Make underlined text (Markdown)
@ -115,7 +117,7 @@ def underline(*content, sep=" "):
return markdown_decoration.underline(value=markdown_decoration.quote(_join(*content, sep=sep)))
def hunderline(*content, sep=" "):
def hunderline(*content: Any, sep: str = " ") -> str:
"""
Make underlined text (HTML)
@ -126,7 +128,7 @@ def hunderline(*content, sep=" "):
return html_decoration.underline(value=html_decoration.quote(_join(*content, sep=sep)))
def strikethrough(*content, sep=" "):
def strikethrough(*content: Any, sep: str = " ") -> str:
"""
Make strikethrough text (Markdown)
@ -139,7 +141,7 @@ def strikethrough(*content, sep=" "):
)
def hstrikethrough(*content, sep=" "):
def hstrikethrough(*content: Any, sep: str = " ") -> str:
"""
Make strikethrough text (HTML)