Skip to content

Commit

Permalink
Removed typeguard dependency
Browse files Browse the repository at this point in the history
Fixes #80.
  • Loading branch information
agronholm committed May 26, 2023
1 parent 4a14fbb commit efd220d
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 37 deletions.
2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions docs/userguide/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------

Expand Down
4 changes: 4 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Version history

This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.

**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
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 0 additions & 4 deletions src/asphalt/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {}

Expand Down Expand Up @@ -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:
Expand Down
11 changes: 0 additions & 11 deletions src/asphalt/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
7 changes: 0 additions & 7 deletions src/asphalt/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
4 changes: 0 additions & 4 deletions src/asphalt/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit efd220d

Please sign in to comment.