From efd220d55eb200dd295bc1fc049572db5fb39fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Fri, 26 May 2023 23:35:07 +0300 Subject: [PATCH] Removed typeguard dependency Fixes #80. --- README.rst | 2 -- docs/userguide/components.rst | 8 -------- docs/versionhistory.rst | 4 ++++ pyproject.toml | 1 - src/asphalt/core/component.py | 4 ---- src/asphalt/core/context.py | 11 ----------- src/asphalt/core/event.py | 7 ------- src/asphalt/core/utils.py | 4 ---- 8 files changed, 4 insertions(+), 37 deletions(-) diff --git a/README.rst b/README.rst index 2161a5e..6cd8ccb 100644 --- a/README.rst +++ b/README.rst @@ -20,8 +20,6 @@ Its highlight features are: event-driven interactions * Supports uvloop_ and tokio_ as event loop policy providers (though YMMV with the last one) * Elegant handling of blocking APIs through the use of thread pooling -* Run time type checking for development and testing to fail early when functions are called with - incompatible arguments (can be disabled with **zero** overhead for production deployments!) * `Type hints`_ and `semantic versioning`_ used throughout the core and all component libraries Asphalt can be used to make any imaginable kind of networked application, ranging from trivial diff --git a/docs/userguide/components.rst b/docs/userguide/components.rst index a6bdc35..3bc2613 100644 --- a/docs/userguide/components.rst +++ b/docs/userguide/components.rst @@ -33,14 +33,6 @@ The reason official Asphalt libraries do not usually do this is that most of the of providing multiple instances of their services, which is obviously not possible when you only add the component itself as a resource. -.. hint:: - It is a good idea to use `type hints`_ with typeguard_ checks - (``assert check_argument_types()``) in the component's ``__init__`` method to ensure that the - received configuration values are of the expected type, but this is of course not required. - -.. _type hints: https://www.python.org/dev/peps/pep-0484/ -.. _typeguard: https://pypi.python.org/pypi/typeguard - Container components -------------------- diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index dc1e1ef..501c139 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -3,6 +3,10 @@ Version history This library adheres to `Semantic Versioning 2.0 `_. +**UNRELEASED** + +- Removed explicit run-time argument type checks and the ``typeguard`` dependency + **4.11.1** (2023-03-23) - Worked around the presence of the ``importlib_metadata`` module on Python 3.10 and diff --git a/pyproject.toml b/pyproject.toml index 7c9b880..5dc4d73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,6 @@ dependencies = [ "importlib_metadata >= 4.4; python_version < '3.10'", "typing_extensions; python_version < '3.10'", "ruamel.yaml >= 0.15", - "typeguard ~= 2.0", "async-generator ~= 1.4", "asyncio_extras ~= 1.3", "async_timeout >= 2.0", diff --git a/src/asphalt/core/component.py b/src/asphalt/core/component.py index 9ecc528..7519e81 100644 --- a/src/asphalt/core/component.py +++ b/src/asphalt/core/component.py @@ -11,8 +11,6 @@ from typing import Any, Dict, Optional, Type, Union from warnings import warn -from typeguard import check_argument_types - from asphalt.core.context import Context from asphalt.core.utils import PluginContainer, merge_config, qualified_name @@ -61,7 +59,6 @@ class ContainerComponent(Component): def __init__( self, components: Optional[Dict[str, Optional[Dict[str, Any]]]] = None ) -> None: - assert check_argument_types() self.child_components: OrderedDict[str, Component] = OrderedDict() self.component_configs = components or {} @@ -90,7 +87,6 @@ def add_component( :param config: keyword arguments passed to the component's constructor """ - assert check_argument_types() if not isinstance(alias, str) or not alias: raise TypeError("component_alias must be a nonempty string") if alias in self.child_components: diff --git a/src/asphalt/core/context.py b/src/asphalt/core/context.py index 8eed775..cc92a0d 100644 --- a/src/asphalt/core/context.py +++ b/src/asphalt/core/context.py @@ -69,7 +69,6 @@ import asyncio_extras from async_generator import async_generator -from typeguard import check_argument_types from asphalt.core.event import Event, Signal, wait_event from asphalt.core.utils import callable_name, qualified_name @@ -261,7 +260,6 @@ class Context: _reset_token: Token def __init__(self, parent: Optional[Context] = None) -> None: - assert check_argument_types() if parent is None: self._parent = _current_context.get(None) else: @@ -350,7 +348,6 @@ def add_teardown_callback( (or ``None`` if the context ended cleanly) """ - assert check_argument_types() self._check_closed() self._teardown_callbacks.append((callback, pass_exception)) @@ -463,8 +460,6 @@ def add_resource( existing one in any way """ - # TODO: re-enable when typeguard properly identifies parametrized types as types - # assert check_argument_types() self._check_closed() if types: if ( @@ -637,8 +632,6 @@ def get_resource( :return: the requested resource, or ``None`` if none was available """ - # TODO: re-enable when typeguard properly identifies parametrized types as types - # assert check_argument_types() self._check_closed() key = (type, name) @@ -679,8 +672,6 @@ def get_resources(self, type: Type[T_Resource]) -> Set[T_Resource]: :return: a set of all found resources of the given type """ - assert check_argument_types() - # Collect all the matching resources from this context resources: Dict[str, T_Resource] = { container.name: container.value_or_factory @@ -798,7 +789,6 @@ def call_in_executor( :return: an awaitable that resolves to the return value of the call """ - assert check_argument_types() if isinstance(executor, str): executor = self.require_resource(Executor, executor) @@ -818,7 +808,6 @@ def threadpool(self, executor: Union[Executor, str, None] = None): :return: an asynchronous context manager """ - assert check_argument_types() if isinstance(executor, str): executor = self.require_resource(Executor, executor) diff --git a/src/asphalt/core/event.py b/src/asphalt/core/event.py index ac71355..151896c 100644 --- a/src/asphalt/core/event.py +++ b/src/asphalt/core/event.py @@ -25,8 +25,6 @@ ) from weakref import WeakKeyDictionary -from typeguard import check_argument_types - from asphalt.core.utils import qualified_name if sys.version_info >= (3, 10): @@ -98,7 +96,6 @@ def __init__( source: Any = None, topic: Optional[str] = None, ) -> None: - assert check_argument_types() self.event_class = event_class self.topic = topic if source is not None: @@ -143,7 +140,6 @@ def connect(self, callback: Callable[[T_Event], Any]) -> Callable[[T_Event], Any :return: the value of ``callback`` argument """ - assert check_argument_types() if self.listeners is None: self.listeners = [] if callback not in self.listeners: @@ -162,7 +158,6 @@ def disconnect(self, callback: Callable) -> None: :param callback: the callable to remove """ - assert check_argument_types() try: if self.listeners is not None: self.listeners.remove(callback) @@ -301,7 +296,6 @@ def cleanup() -> None: queue = None - assert check_argument_types() queue = Queue(max_queue_size) for signal in signals: signal.connect(queue.put_nowait) @@ -326,6 +320,5 @@ async def wait_event( :return: the event that was dispatched """ - assert check_argument_types() async with aclosing(stream_events(signals, filter)) as events: return await events.asend(None) diff --git a/src/asphalt/core/utils.py b/src/asphalt/core/utils.py index bbf7e60..8bf793b 100644 --- a/src/asphalt/core/utils.py +++ b/src/asphalt/core/utils.py @@ -13,8 +13,6 @@ from inspect import isclass from typing import Any, Callable, Dict, List, Optional, Type, TypeVar, Union, overload -from typeguard import check_argument_types - if sys.version_info >= (3, 10): from importlib.metadata import entry_points else: @@ -98,7 +96,6 @@ def merge_config( :return: the merge result """ - assert check_argument_types() copied = original.copy() if original else {} if overrides: for key, value in overrides.items(): @@ -181,7 +178,6 @@ def create_object(self, type: Union[Type, str], **constructor_kwargs) -> Any: :return: the plugin instance """ - assert check_argument_types() assert self.base_class, "base class has not been defined" plugin_class = self.resolve(type) if not isclass(plugin_class) or not issubclass(plugin_class, self.base_class):