Remove kwargs copy in TelegramEventObserver.trigger and remove __deepcopy__ method from AiohttpSession

This commit is contained in:
Alex Root Junior 2020-01-13 21:30:06 +02:00
parent 824b672513
commit b61cc04e9a
3 changed files with 2 additions and 25 deletions

View file

@ -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

View file

@ -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

View file

@ -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