mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Format code with black, autopep8 and isort
This commit fixes the style issues introduced in6224a23according to the output from black, autopep8 and isort. Details:d34ab172-6018-42f2-a268-59f8d3b78f55/
This commit is contained in:
parent
6224a232ea
commit
044f38ce36
1 changed files with 42 additions and 18 deletions
|
|
@ -13,29 +13,45 @@ from .fields import BaseField
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
from ..bot.bot import Bot
|
from ..bot.bot import Bot
|
||||||
|
|
||||||
__all__ = ('MetaTelegramObject', 'TelegramObject', 'InputFile', 'String', 'Integer', 'Float', 'Boolean')
|
__all__ = (
|
||||||
|
"MetaTelegramObject",
|
||||||
|
"TelegramObject",
|
||||||
|
"InputFile",
|
||||||
|
"String",
|
||||||
|
"Integer",
|
||||||
|
"Float",
|
||||||
|
"Boolean",
|
||||||
|
)
|
||||||
|
|
||||||
PROPS_ATTR_NAME = '_props'
|
PROPS_ATTR_NAME = "_props"
|
||||||
VALUES_ATTR_NAME = '_values'
|
VALUES_ATTR_NAME = "_values"
|
||||||
ALIASES_ATTR_NAME = '_aliases'
|
ALIASES_ATTR_NAME = "_aliases"
|
||||||
|
|
||||||
# Binding of builtin types
|
# Binding of builtin types
|
||||||
InputFile = TypeVar('InputFile', 'InputFile', io.BytesIO, io.FileIO, str)
|
InputFile = TypeVar("InputFile", "InputFile", io.BytesIO, io.FileIO, str)
|
||||||
String = TypeVar('String', bound=str)
|
String = TypeVar("String", bound=str)
|
||||||
Integer = TypeVar('Integer', bound=int)
|
Integer = TypeVar("Integer", bound=int)
|
||||||
Float = TypeVar('Float', bound=float)
|
Float = TypeVar("Float", bound=float)
|
||||||
Boolean = TypeVar('Boolean', bound=bool)
|
Boolean = TypeVar("Boolean", bound=bool)
|
||||||
T = TypeVar('T')
|
T = TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
class MetaTelegramObject(type):
|
class MetaTelegramObject(type):
|
||||||
"""
|
"""
|
||||||
Metaclass for telegram objects
|
Metaclass for telegram objects
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_objects = {}
|
_objects = {}
|
||||||
|
|
||||||
def __new__(mcs: typing.Type[T], name: str, bases: typing.Tuple[typing.Type], namespace: typing.Dict[str, typing.Any], **kwargs: typing.Any) -> T:
|
def __new__(
|
||||||
cls = super(MetaTelegramObject, mcs).__new__(mcs, name, bases, namespace)
|
mcs: typing.Type[T],
|
||||||
|
name: str,
|
||||||
|
bases: typing.Tuple[typing.Type],
|
||||||
|
namespace: typing.Dict[str, typing.Any],
|
||||||
|
**kwargs: typing.Any
|
||||||
|
) -> T:
|
||||||
|
cls = super(MetaTelegramObject, mcs).__new__(
|
||||||
|
mcs, name, bases, namespace)
|
||||||
|
|
||||||
props = {}
|
props = {}
|
||||||
values = {}
|
values = {}
|
||||||
|
|
@ -50,7 +66,11 @@ class MetaTelegramObject(type):
|
||||||
aliases.update(getattr(base, ALIASES_ATTR_NAME))
|
aliases.update(getattr(base, ALIASES_ATTR_NAME))
|
||||||
|
|
||||||
# Scan current object for props
|
# Scan current object for props
|
||||||
for name, prop in ((name, prop) for name, prop in namespace.items() if isinstance(prop, BaseField)):
|
for name, prop in (
|
||||||
|
(name, prop)
|
||||||
|
for name, prop in namespace.items()
|
||||||
|
if isinstance(prop, BaseField)
|
||||||
|
):
|
||||||
props[prop.alias] = prop
|
props[prop.alias] = prop
|
||||||
if prop.default is not None:
|
if prop.default is not None:
|
||||||
values[prop.alias] = prop.default
|
values[prop.alias] = prop.default
|
||||||
|
|
@ -75,7 +95,9 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject):
|
||||||
Abstract class for telegram objects
|
Abstract class for telegram objects
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, conf: typing.Dict[str, typing.Any]=None, **kwargs: typing.Any) -> None:
|
def __init__(
|
||||||
|
self, conf: typing.Dict[str, typing.Any] = None, **kwargs: typing.Any
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Deserialize object
|
Deserialize object
|
||||||
|
|
||||||
|
|
@ -151,9 +173,11 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject):
|
||||||
|
|
||||||
bot = Bot.get_current()
|
bot = Bot.get_current()
|
||||||
if bot is None:
|
if bot is None:
|
||||||
raise RuntimeError("Can't get bot instance from context. "
|
raise RuntimeError(
|
||||||
"You can fix it with setting current instance: "
|
"Can't get bot instance from context. "
|
||||||
"'Bot.set_current(bot_instance)'")
|
"You can fix it with setting current instance: "
|
||||||
|
"'Bot.set_current(bot_instance)'"
|
||||||
|
)
|
||||||
return bot
|
return bot
|
||||||
|
|
||||||
def to_python(self) -> typing.Dict[str, typing.Any]:
|
def to_python(self) -> typing.Dict[str, typing.Any]:
|
||||||
|
|
@ -224,7 +248,7 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject):
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if key in self.props:
|
if key in self.props:
|
||||||
return self.props[key].set_value(self, value, self.conf.get('parent', None))
|
return self.props[key].set_value(self, value, self.conf.get("parent", None))
|
||||||
raise KeyError(key)
|
raise KeyError(key)
|
||||||
|
|
||||||
def __contains__(self, item: str) -> bool:
|
def __contains__(self, item: str) -> bool:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue