From b61cc04e9a0f9e2aded008abf90b300cf3c915d4 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Mon, 13 Jan 2020 21:30:06 +0200 Subject: [PATCH] Remove kwargs copy in TelegramEventObserver.trigger and remove __deepcopy__ method from AiohttpSession --- aiogram/api/client/session/aiohttp.py | 14 -------------- aiogram/dispatcher/event/observer.py | 5 ++--- .../test_session/test_aiohttp_session.py | 8 -------- 3 files changed, 2 insertions(+), 25 deletions(-) diff --git a/aiogram/api/client/session/aiohttp.py b/aiogram/api/client/session/aiohttp.py index 28ca6db0..caced193 100644 --- a/aiogram/api/client/session/aiohttp.py +++ b/aiogram/api/client/session/aiohttp.py @@ -60,17 +60,3 @@ class AiohttpSession(BaseSession): async def __aenter__(self) -> AiohttpSession: await self.create_session() return self - - def __deepcopy__(self: T, memo: Optional[Dict[int, Any]] = None) -> T: - if memo is None: # pragma: no cover - # This block was never be called - memo = {} - - cls = self.__class__ - result = cls.__new__(cls) - memo[id(self)] = result - for key, value in self.__dict__.items(): - # aiohttp ClientSession cannot be copied. - copied_value = copy.deepcopy(value, memo=memo) if key != "_session" else None - setattr(result, key, copied_value) - return result diff --git a/aiogram/dispatcher/event/observer.py b/aiogram/dispatcher/event/observer.py index 40afc180..fdec4fc6 100644 --- a/aiogram/dispatcher/event/observer.py +++ b/aiogram/dispatcher/event/observer.py @@ -155,12 +155,11 @@ class TelegramEventObserver(EventObserver): Handler will be called when all its filters is pass. """ for handler in self.handlers: - kwargs_copy = copy.copy(kwargs) result, data = await handler.check(*args, **kwargs) if result: - kwargs_copy.update(data) + kwargs.update(data) try: - yield await handler.call(*args, **kwargs_copy) + yield await handler.call(*args, **kwargs) except SkipHandler: continue break diff --git a/tests/test_api/test_client/test_session/test_aiohttp_session.py b/tests/test_api/test_client/test_session/test_aiohttp_session.py index ac93b1a7..2ebcc7b4 100644 --- a/tests/test_api/test_client/test_session/test_aiohttp_session.py +++ b/tests/test_api/test_client/test_session/test_aiohttp_session.py @@ -123,11 +123,3 @@ class TestAiohttpSession: assert session == ctx mocked_close.awaited_once() mocked_create_session.awaited_once() - - @pytest.mark.asyncio - async def test_deepcopy(self): - # Session should be copied without aiohttp.ClientSession - async with AiohttpSession() as session: - cloned_session = copy.deepcopy(session) - assert cloned_session != session - assert cloned_session._session is None