From 98529acae88e5c0388c139c51fcca12610e13a7e Mon Sep 17 00:00:00 2001 From: Pavel Perestoronin Date: Fri, 17 Nov 2023 16:52:04 +0100 Subject: [PATCH] =?UTF-8?q?OPT:=20rename=20`BaseBoundService`=20internal?= =?UTF-8?q?=20attributes=20to=20avoid=20name=20clashing=20=F0=9F=A7=91?= =?UTF-8?q?=E2=80=8D=F0=9F=92=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- combadge/core/binder.py | 2 +- combadge/core/service.py | 20 ++++++++++---------- tests/core/test_binder.py | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/combadge/core/binder.py b/combadge/core/binder.py index 6b27f24..1dde426 100644 --- a/combadge/core/binder.py +++ b/combadge/core/binder.py @@ -47,7 +47,7 @@ def bind_class( class BoundService(BaseBoundService, from_protocol): # type: ignore[misc, valid-type] """Bound service class that implements the protocol.""" - _protocol = from_protocol + __combadge_protocol__ = from_protocol for name, method in _enumerate_methods(from_protocol): signature = Signature.from_method(method) diff --git a/combadge/core/service.py b/combadge/core/service.py index 3acc449..c3605ae 100644 --- a/combadge/core/service.py +++ b/combadge/core/service.py @@ -9,16 +9,16 @@ class BaseBoundService(Generic[BackendT]): """Base for dynamically generated service classes.""" - _protocol: ClassVar[Type] + __combadge_protocol__: ClassVar[Type] - backend: BackendT - __slots__ = ("backend",) + __combadge_backend__: BackendT + __slots__ = ("__combadge_backend__",) def __init__(self, backend: BackendT) -> None: # noqa: D107 - self.backend = backend + self.__combadge_backend__ = backend def __enter__(self) -> Self: - self.backend.__enter__() # type: ignore[attr-defined] + self.__combadge_backend__.__enter__() # type: ignore[attr-defined] return self def __exit__( @@ -28,12 +28,12 @@ def __exit__( traceback: Optional[TracebackType], ) -> Any: # Remove the freed instance from the cache: - del self.backend[self._protocol] # type: ignore[attr-defined] + del self.__combadge_backend__[self.__combadge_protocol__] # type: ignore[attr-defined] - return self.backend.__exit__(exc_type, exc_value, traceback) # type: ignore[attr-defined] + return self.__combadge_backend__.__exit__(exc_type, exc_value, traceback) # type: ignore[attr-defined] async def __aenter__(self) -> Self: - await self.backend.__aenter__() # type: ignore[attr-defined] + await self.__combadge_backend__.__aenter__() # type: ignore[attr-defined] return self async def __aexit__( @@ -43,6 +43,6 @@ async def __aexit__( traceback: Optional[TracebackType], ) -> Any: # Remove the freed instance from the cache: - del self.backend[self._protocol] # type: ignore[attr-defined] + del self.__combadge_backend__[self.__combadge_protocol__] # type: ignore[attr-defined] - return await self.backend.__aexit__(exc_type, exc_value, traceback) # type: ignore[attr-defined] + return await self.__combadge_backend__.__aexit__(exc_type, exc_value, traceback) # type: ignore[attr-defined] diff --git a/tests/core/test_binder.py b/tests/core/test_binder.py index 1fdfabb..867a380 100644 --- a/tests/core/test_binder.py +++ b/tests/core/test_binder.py @@ -70,7 +70,7 @@ class ServiceProtocol(Protocol): service = bind(ServiceProtocol, Mock()) # type: ignore[type-abstract] assert isinstance(service, BaseBoundService) - assert service._protocol is ServiceProtocol + assert service.__combadge_protocol__ is ServiceProtocol def test_service_type() -> None: