Fix style errors

This commit is contained in:
Boger 2020-03-25 15:57:25 +03:00
parent 7db1572fd3
commit 23c632b37b
7 changed files with 8 additions and 14 deletions

View file

@ -111,9 +111,7 @@ from ..types import (
UserProfilePhotos, UserProfilePhotos,
WebhookInfo, WebhookInfo,
) )
from ...utils.mixins import ( from ...utils.mixins import ContextInstanceMixin
ContextInstanceMixin,
)
from ...utils.token import ( from ...utils.token import (
validate_token, validate_token,
extract_bot_id, extract_bot_id,

View file

@ -1,6 +1,5 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import ( from typing import (
Optional,
TYPE_CHECKING, TYPE_CHECKING,
Any, Any,
Dict, Dict,

View file

@ -27,6 +27,5 @@ class MessageHandlerCommandMixin(BaseHandlerMixin[Message]):
@property @property
def command(self) -> Optional[CommandObject]: def command(self) -> Optional[CommandObject]:
if "command" in self.data: if "command" in self.data:
# TODO: remove cast
return cast(CommandObject, self.data["command"]) return cast(CommandObject, self.data["command"])
return None return None

View file

@ -58,16 +58,16 @@ class ContextInstanceMixin(Generic[ContextInstance]):
@overload # noqa: F811, it's overload, not redefinition @overload # noqa: F811, it's overload, not redefinition
@classmethod @classmethod
def get_current(cls, no_error: Literal[True]) -> Optional[ContextInstance]: def get_current(cls, no_error: Literal[True]) -> Optional[ContextInstance]: # noqa: F811
... ...
@overload # noqa: F811, it's overload, not redefinition @overload # noqa: F811, it's overload, not redefinition
@classmethod @classmethod
def get_current(cls, no_error: Literal[False]) -> ContextInstance: def get_current(cls, no_error: Literal[False]) -> ContextInstance: # noqa: F811
... ...
@classmethod # noqa: F811, it's overload, not redefinition @classmethod # noqa: F811, it's overload, not redefinition
def get_current(cls, no_error: bool = True) -> Optional[ContextInstance]: def get_current(cls, no_error: bool = True) -> Optional[ContextInstance]: # noqa: F811
# on mypy 0.770 I catch that contextvars.ContextVar always contextvars.ContextVar[Any] # on mypy 0.770 I catch that contextvars.ContextVar always contextvars.ContextVar[Any]
cls.__context_instance = cast( cls.__context_instance = cast(
contextvars.ContextVar[ContextInstance], cls.__context_instance contextvars.ContextVar[ContextInstance], cls.__context_instance

View file

@ -55,9 +55,7 @@ class TestBaseBot:
with patch( with patch(
"aiogram.api.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock "aiogram.api.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
) as mocked_close: ) as mocked_close:
async with Bot("42:TEST", session=AiohttpSession()).context( async with Bot("42:TEST", session=AiohttpSession()).context(auto_close=close) as bot:
auto_close=close
) as bot:
assert isinstance(bot, Bot) assert isinstance(bot, Bot)
if close: if close:
mocked_close.assert_awaited() mocked_close.assert_awaited()

View file

@ -30,7 +30,7 @@ class CustomSession(BaseSession):
yield b"\f" * 10 yield b"\f" * 10
class TestBaseSession(): class TestBaseSession:
def test_init_api(self): def test_init_api(self):
session = CustomSession() session = CustomSession()
assert session.api == PRODUCTION assert session.api == PRODUCTION

View file

@ -6,7 +6,7 @@ from aiogram.utils.mixins import (
) )
class ContextObject(ContextInstanceMixin['ContextObject']): class ContextObject(ContextInstanceMixin["ContextObject"]):
pass pass