diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index dd3ace05..fbeb126d 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -51,7 +51,7 @@ jobs: uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} - + check: # This job does nothing and is only used for the branch protection name: ✅ Ensure the required checks passing if: always() diff --git a/mode/debug.py b/mode/debug.py index 29975fc9..49b62ba4 100644 --- a/mode/debug.py +++ b/mode/debug.py @@ -1,4 +1,5 @@ """Debugging utilities.""" + import math import signal import traceback diff --git a/mode/locals.py b/mode/locals.py index 5869089c..02ad9485 100644 --- a/mode/locals.py +++ b/mode/locals.py @@ -72,6 +72,7 @@ class XProxy(MutableMappingRole, AsyncContextManagerRole): ... x['foo'] 'value' """ + import sys import typing from collections import deque @@ -518,8 +519,7 @@ def _get_sequence(self) -> Sequence[T_co]: return cast(Sequence[T_co], obj) @overload - def __getitem__(self, i: int) -> T_co: - ... + def __getitem__(self, i: int) -> T_co: ... @overload # noqa: F811 def __getitem__(self, s: slice) -> MutableSequence[T_co]: # noqa: F811 @@ -562,8 +562,7 @@ def insert(self, index: int, object: T) -> None: self._get_sequence().insert(index, object) @overload - def __setitem__(self, i: int, o: T) -> None: - ... + def __setitem__(self, i: int, o: T) -> None: ... @overload # noqa: F811 def __setitem__(self, s: slice, o: Iterable[T]) -> None: # noqa: F811 @@ -573,8 +572,7 @@ def __setitem__(self, index_or_slice: Any, o: Any) -> None: # noqa: F811 self._get_sequence().__setitem__(index_or_slice, o) @overload - def __delitem__(self, i: int) -> None: - ... + def __delitem__(self, i: int) -> None: ... @overload # noqa: F811 def __delitem__(self, i: slice) -> None: # noqa: F811 @@ -746,8 +744,7 @@ def __getitem__(self, key: KT) -> VT_co: return self._get_mapping().__getitem__(key) @overload - def get(self, k: KT) -> Optional[VT_co]: - ... + def get(self, k: KT) -> Optional[VT_co]: ... @overload # noqa: F811 def get(self, k: KT, default: Union[VT_co, T]) -> Union[VT_co, T]: # noqa: F811 @@ -796,8 +793,7 @@ def clear(self) -> None: self._get_mapping().clear() @overload - def pop(self, k: KT) -> VT: - ... + def pop(self, k: KT) -> VT: ... @overload # noqa: F811 def pop(self, k: KT, default: Union[VT, T] = ...) -> Union[VT, T]: # noqa: F811 @@ -813,8 +809,7 @@ def setdefault(self, k: KT, *args: Any) -> VT: return self._get_mapping().setdefault(k, *args) @overload - def update(self, __m: Mapping[KT, VT], **kwargs: VT) -> None: - ... + def update(self, __m: Mapping[KT, VT], **kwargs: VT) -> None: ... @overload # noqa: F811 def update(self, __m: Iterable[Tuple[KT, VT]], **kwargs: VT) -> None: # noqa: F811 diff --git a/mode/loop/_gevent_loop.py b/mode/loop/_gevent_loop.py index 0ecb284f..e2125ecb 100644 --- a/mode/loop/_gevent_loop.py +++ b/mode/loop/_gevent_loop.py @@ -1,4 +1,5 @@ """Gevent loop customizations.""" + import asyncio from typing import Any diff --git a/mode/loop/eventlet.py b/mode/loop/eventlet.py index 1f77a24a..08aa0452 100644 --- a/mode/loop/eventlet.py +++ b/mode/loop/eventlet.py @@ -1,4 +1,5 @@ """Enable :pypi:`eventlet` support for :mod:`asyncio`.""" + import asyncio # noqa: E402,I100,I202 import os diff --git a/mode/loop/gevent.py b/mode/loop/gevent.py index ef254405..25589dbb 100644 --- a/mode/loop/gevent.py +++ b/mode/loop/gevent.py @@ -1,4 +1,5 @@ """Enable :pypi:`gevent` support for :mod:`asyncio`.""" + import asyncio # noqa: E402,I100,I202 import os import warnings diff --git a/mode/loop/uvloop.py b/mode/loop/uvloop.py index 145b780c..3304aac2 100644 --- a/mode/loop/uvloop.py +++ b/mode/loop/uvloop.py @@ -1,4 +1,5 @@ """Enable :pypi:`uvloop` as the event loop for :mod:`asyncio`.""" + import asyncio import uvloop diff --git a/mode/proxy.py b/mode/proxy.py index d92bdcce..e8e664da 100644 --- a/mode/proxy.py +++ b/mode/proxy.py @@ -2,6 +2,7 @@ Works like a service, but delegates to underlying service object. """ + import abc from typing import Any, ContextManager, Optional diff --git a/mode/services.py b/mode/services.py index 21713efe..e43b2f3e 100644 --- a/mode/services.py +++ b/mode/services.py @@ -1,4 +1,5 @@ """Async I/O services that can be started/stopped/shutdown.""" + import asyncio import logging import sys @@ -674,8 +675,7 @@ def __post_init__(self) -> None: """Additional user initialization.""" ... - def on_init(self) -> None: - ... # deprecated: use __post_init__ + def on_init(self) -> None: ... # deprecated: use __post_init__ def on_init_dependencies(self) -> Iterable[ServiceT]: """Return list of service dependencies for this service.""" diff --git a/mode/signals.py b/mode/signals.py index 2ba5a9d1..efc62a94 100644 --- a/mode/signals.py +++ b/mode/signals.py @@ -1,4 +1,5 @@ """Signals - implementation of the Observer pattern.""" + import asyncio from collections import defaultdict from functools import partial diff --git a/mode/supervisors.py b/mode/supervisors.py index 98ebd4ac..d21af4a2 100644 --- a/mode/supervisors.py +++ b/mode/supervisors.py @@ -6,6 +6,7 @@ http://learnyousomeerlang.com/supervisors """ + import asyncio from typing import Any, Awaitable, Callable, Dict, List, Optional, Type diff --git a/mode/threads.py b/mode/threads.py index bd9214f0..1efd4102 100644 --- a/mode/threads.py +++ b/mode/threads.py @@ -6,6 +6,7 @@ Note: To stop something using the thread's loop, you have to use the ``on_thread_stop`` callback instead of the on_stop callback. """ + import asyncio import sys import threading @@ -117,11 +118,9 @@ def __init__( super().__init__(loop=self.thread_loop, **kwargs) assert self._shutdown.loop is self.parent_loop - async def on_thread_started(self) -> None: - ... + async def on_thread_started(self) -> None: ... - async def on_thread_stop(self) -> None: - ... + async def on_thread_stop(self) -> None: ... # The deal with asyncio.Event and threads. # @@ -226,14 +225,13 @@ def _stopped_set(self) -> None: def set_shutdown(self) -> None: self.parent_loop.call_soon_threadsafe(self._shutdown.set) - async def _stop_children(self) -> None: - ... # called by thread instead of .stop() + async def _stop_children(self) -> None: ... # called by thread instead of .stop() - async def _stop_futures(self) -> None: - ... # called by thread instead of .stop() + async def _stop_futures(self) -> None: ... # called by thread instead of .stop() - async def _stop_exit_stacks(self) -> None: - ... # called by thread instead of .stop() + async def _stop_exit_stacks( + self, + ) -> None: ... # called by thread instead of .stop() async def _shutdown_thread(self) -> None: await self.on_thread_stop() diff --git a/mode/timers.py b/mode/timers.py index ef38d670..9928a06f 100644 --- a/mode/timers.py +++ b/mode/timers.py @@ -1,4 +1,5 @@ """AsyncIO Timers.""" + import asyncio from itertools import count from time import perf_counter diff --git a/mode/types/services.py b/mode/types/services.py index 2d190610..fb1e0795 100644 --- a/mode/types/services.py +++ b/mode/types/services.py @@ -1,4 +1,5 @@ """Type classes for :mod:`mode.services`.""" + import abc import asyncio from typing import ( @@ -37,16 +38,13 @@ class DiagT(abc.ABC): last_transition: MutableMapping[str, float] @abc.abstractmethod - def __init__(self, service: "ServiceT") -> None: - ... + def __init__(self, service: "ServiceT") -> None: ... @abc.abstractmethod - def set_flag(self, flag: str) -> None: - ... + def set_flag(self, flag: str) -> None: ... @abc.abstractmethod - def unset_flag(self, flag: str) -> None: - ... + def unset_flag(self, flag: str) -> None: ... class ServiceT(AsyncContextManager): @@ -70,117 +68,90 @@ class ServiceT(AsyncContextManager): @abc.abstractmethod def __init__( self, *, beacon: NodeT = None, loop: asyncio.AbstractEventLoop = None - ) -> None: - ... + ) -> None: ... @abc.abstractmethod - def add_dependency(self, service: "ServiceT") -> "ServiceT": - ... + def add_dependency(self, service: "ServiceT") -> "ServiceT": ... @abc.abstractmethod - async def add_runtime_dependency(self, service: "ServiceT") -> "ServiceT": - ... + async def add_runtime_dependency(self, service: "ServiceT") -> "ServiceT": ... @abc.abstractmethod - async def add_async_context(self, context: AsyncContextManager) -> Any: - ... + async def add_async_context(self, context: AsyncContextManager) -> Any: ... @abc.abstractmethod - def add_context(self, context: ContextManager) -> Any: - ... + def add_context(self, context: ContextManager) -> Any: ... @abc.abstractmethod - async def start(self) -> None: - ... + async def start(self) -> None: ... @abc.abstractmethod - async def maybe_start(self) -> bool: - ... + async def maybe_start(self) -> bool: ... @abc.abstractmethod - async def crash(self, reason: BaseException) -> None: - ... + async def crash(self, reason: BaseException) -> None: ... @abc.abstractmethod - def _crash(self, reason: BaseException) -> None: - ... + def _crash(self, reason: BaseException) -> None: ... @abc.abstractmethod - async def stop(self) -> None: - ... + async def stop(self) -> None: ... @abc.abstractmethod - def service_reset(self) -> None: - ... + def service_reset(self) -> None: ... @abc.abstractmethod - async def restart(self) -> None: - ... + async def restart(self) -> None: ... @abc.abstractmethod - async def wait_until_stopped(self) -> None: - ... + async def wait_until_stopped(self) -> None: ... @abc.abstractmethod - def set_shutdown(self) -> None: - ... + def set_shutdown(self) -> None: ... @abc.abstractmethod - def _repr_info(self) -> str: - ... + def _repr_info(self) -> str: ... @property @abc.abstractmethod - def started(self) -> bool: - ... + def started(self) -> bool: ... @property @abc.abstractmethod - def crashed(self) -> bool: - ... + def crashed(self) -> bool: ... @property @abc.abstractmethod - def should_stop(self) -> bool: - ... + def should_stop(self) -> bool: ... @property @abc.abstractmethod - def state(self) -> str: - ... + def state(self) -> str: ... @property @abc.abstractmethod - def label(self) -> str: - ... + def label(self) -> str: ... @property @abc.abstractmethod - def shortlabel(self) -> str: - ... + def shortlabel(self) -> str: ... @property - def beacon(self) -> NodeT: - ... + def beacon(self) -> NodeT: ... @beacon.setter - def beacon(self, beacon: NodeT) -> None: - ... + def beacon(self, beacon: NodeT) -> None: ... @property @abc.abstractmethod - def loop(self) -> asyncio.AbstractEventLoop: - ... + def loop(self) -> asyncio.AbstractEventLoop: ... @loop.setter - def loop(self, loop: Optional[asyncio.AbstractEventLoop]) -> None: - ... + def loop(self, loop: Optional[asyncio.AbstractEventLoop]) -> None: ... @property @abc.abstractmethod - def crash_reason(self) -> Optional[BaseException]: - ... + def crash_reason(self) -> Optional[BaseException]: ... @crash_reason.setter - def crash_reason(self, reason: Optional[BaseException]) -> None: - ... + def crash_reason(self, reason: Optional[BaseException]) -> None: ... diff --git a/mode/types/signals.py b/mode/types/signals.py index 8c8396cb..e9d10355 100644 --- a/mode/types/signals.py +++ b/mode/types/signals.py @@ -1,4 +1,5 @@ """Type classes for :mod:`mode.signals`.""" + import abc import asyncio import typing @@ -71,67 +72,54 @@ def __init__( default_sender: Any = None, receivers: MutableSet[SignalHandlerRefT] = None, filter_receivers: FilterReceiverMapping = None - ) -> None: - ... + ) -> None: ... @abc.abstractmethod - def clone(self, **kwargs: Any) -> "BaseSignalT": - ... + def clone(self, **kwargs: Any) -> "BaseSignalT": ... @abc.abstractmethod - def with_default_sender(self, sender: Any = None) -> "BaseSignalT": - ... + def with_default_sender(self, sender: Any = None) -> "BaseSignalT": ... @abc.abstractmethod - def connect(self, fun: SignalHandlerT, **kwargs: Any) -> Callable: - ... + def connect(self, fun: SignalHandlerT, **kwargs: Any) -> Callable: ... @abc.abstractmethod def disconnect( self, fun: SignalHandlerT, *, sender: Any = None, weak: bool = True - ) -> None: - ... + ) -> None: ... class SignalT(BaseSignalT[T]): """Base class for all async signals (using ``async def``).""" @abc.abstractmethod - async def __call__(self, sender: T_contra, *args: Any, **kwargs: Any) -> None: - ... + async def __call__(self, sender: T_contra, *args: Any, **kwargs: Any) -> None: ... @abc.abstractmethod - async def send(self, sender: T_contra, *args: Any, **kwargs: Any) -> None: - ... + async def send(self, sender: T_contra, *args: Any, **kwargs: Any) -> None: ... @typing.no_type_check @abc.abstractmethod - def clone(self, **kwargs: Any) -> "SignalT": - ... + def clone(self, **kwargs: Any) -> "SignalT": ... @typing.no_type_check @abc.abstractmethod - def with_default_sender(self, sender: Any = None) -> "SignalT": - ... + def with_default_sender(self, sender: Any = None) -> "SignalT": ... class SyncSignalT(BaseSignalT[T]): """Base class for all synchronous signals (using regular ``def``).""" @abc.abstractmethod - def __call__(self, sender: T_contra, *args: Any, **kwargs: Any) -> None: - ... + def __call__(self, sender: T_contra, *args: Any, **kwargs: Any) -> None: ... @abc.abstractmethod - def send(self, sender: T_contra, *args: Any, **kwargs: Any) -> None: - ... + def send(self, sender: T_contra, *args: Any, **kwargs: Any) -> None: ... @typing.no_type_check @abc.abstractmethod - def clone(self, **kwargs: Any) -> "SyncSignalT": - ... + def clone(self, **kwargs: Any) -> "SyncSignalT": ... @typing.no_type_check @abc.abstractmethod - def with_default_sender(self, sender: Any = None) -> "SyncSignalT": - ... + def with_default_sender(self, sender: Any = None) -> "SyncSignalT": ... diff --git a/mode/types/supervisors.py b/mode/types/supervisors.py index 1b2cdfc2..f8214344 100644 --- a/mode/types/supervisors.py +++ b/mode/types/supervisors.py @@ -1,4 +1,5 @@ """Type classes for :mod:`mode.supervisors`.""" + import abc import typing from typing import Any, Awaitable, Callable, Optional, Type @@ -9,8 +10,7 @@ from .services import ServiceT else: - class ServiceT: - ... # noqa: E701 + class ServiceT: ... # noqa: E701 __all__ = ["SupervisorStrategyT"] @@ -38,21 +38,16 @@ def __init__( self.replacement: Optional[ReplacementT] = replacement @abc.abstractmethod - def wakeup(self) -> None: - ... + def wakeup(self) -> None: ... @abc.abstractmethod - def add(self, *services: ServiceT) -> None: - ... + def add(self, *services: ServiceT) -> None: ... @abc.abstractmethod - def discard(self, *services: ServiceT) -> None: - ... + def discard(self, *services: ServiceT) -> None: ... @abc.abstractmethod - def service_operational(self, service: ServiceT) -> bool: - ... + def service_operational(self, service: ServiceT) -> bool: ... @abc.abstractmethod - async def restart_service(self, service: ServiceT) -> None: - ... + async def restart_service(self, service: ServiceT) -> None: ... diff --git a/mode/utils/_py37_contextlib.py b/mode/utils/_py37_contextlib.py index 800765b1..d71ee463 100644 --- a/mode/utils/_py37_contextlib.py +++ b/mode/utils/_py37_contextlib.py @@ -1,4 +1,5 @@ """Backport implementation of Python 3.7 contextlib.""" + import abc import sys import types diff --git a/mode/utils/aiter.py b/mode/utils/aiter.py index 8895de22..ecdafd90 100644 --- a/mode/utils/aiter.py +++ b/mode/utils/aiter.py @@ -1,4 +1,5 @@ """Async iterator lost and found missing methods: aiter, anext, etc.""" + import collections.abc import sys from functools import singledispatch diff --git a/mode/utils/collections.py b/mode/utils/collections.py index 1636108c..93aaa012 100644 --- a/mode/utils/collections.py +++ b/mode/utils/collections.py @@ -1,4 +1,5 @@ """Custom data structures.""" + import abc import collections.abc import threading @@ -49,11 +50,9 @@ from django.utils.functional import LazyObject, LazySettings except ImportError: - class LazyObject: - ... # noqa + class LazyObject: ... # noqa - class LazySettings: - ... # noqa + class LazySettings: ... # noqa __all__ = [ @@ -149,8 +148,7 @@ def __repr__(self) -> str: return repr(self.data) @overload - def __getitem__(self, i: int) -> T: - ... + def __getitem__(self, i: int) -> T: ... @overload # noqa: F811 def __getitem__(self, s: slice) -> MutableSequence[T]: # noqa: F811 @@ -160,8 +158,7 @@ def __getitem__(self, s: Any) -> Any: # noqa: F811 return self.data.__getitem__(s) @overload - def __setitem__(self, i: int, o: T) -> None: - ... + def __setitem__(self, i: int, o: T) -> None: ... @overload # noqa: F811 def __setitem__(self, s: slice, o: Iterable[T]) -> None: # noqa: F811 @@ -171,8 +168,7 @@ def __setitem__(self, index_or_slice: Any, o: Any) -> None: # noqa: F811 self.data.__setitem__(index_or_slice, o) @overload - def __delitem__(self, i: int) -> None: - ... + def __delitem__(self, i: int) -> None: ... @overload # noqa: F811 def __delitem__(self, i: slice) -> None: # noqa: F811 @@ -383,16 +379,13 @@ class FastUserList(UserList): class MappingViewProxy(Generic[KT, VT]): @abc.abstractmethod - def _keys(self) -> Iterator[KT]: - ... + def _keys(self) -> Iterator[KT]: ... @abc.abstractmethod - def _values(self) -> Iterator[VT]: - ... + def _values(self) -> Iterator[VT]: ... @abc.abstractmethod - def _items(self) -> Iterator[Tuple[KT, VT]]: - ... + def _items(self) -> Iterator[Tuple[KT, VT]]: ... class ProxyKeysView(KeysView[KT]): @@ -526,17 +519,13 @@ def __setstate__(self, state: Dict[str, Any]) -> None: class ManagedUserSet(FastUserSet[T]): """A MutableSet that adds callbacks for when keys are get/set/deleted.""" - def on_add(self, value: T) -> None: - ... + def on_add(self, value: T) -> None: ... - def on_discard(self, value: T) -> None: - ... + def on_discard(self, value: T) -> None: ... - def on_clear(self) -> None: - ... + def on_clear(self) -> None: ... - def on_change(self, added: Set[T], removed: Set[T]) -> None: - ... + def on_change(self, added: Set[T], removed: Set[T]) -> None: ... def add(self, element: T) -> None: if element not in self.data: diff --git a/mode/utils/compat.py b/mode/utils/compat.py index 0fbbb8a8..c1907c61 100644 --- a/mode/utils/compat.py +++ b/mode/utils/compat.py @@ -1,4 +1,5 @@ """Compatibility utilities.""" + from typing import IO, AnyStr from .contexts import asyncnullcontext, nullcontext diff --git a/mode/utils/contexts.py b/mode/utils/contexts.py index e2ccc3ec..82e58e79 100644 --- a/mode/utils/contexts.py +++ b/mode/utils/contexts.py @@ -1,4 +1,5 @@ """Context manager utilities.""" + import typing from types import TracebackType from typing import Any, Type @@ -73,5 +74,4 @@ async def __aexit__( exc_type: Type[BaseException] = None, exc_val: BaseException = None, exc_tb: TracebackType = None, - ) -> None: - ... + ) -> None: ... diff --git a/mode/utils/cron.py b/mode/utils/cron.py index a177ceca..a46febaf 100644 --- a/mode/utils/cron.py +++ b/mode/utils/cron.py @@ -1,4 +1,5 @@ """Crontab Utilities.""" + import time from datetime import datetime, tzinfo from typing import cast diff --git a/mode/utils/futures.py b/mode/utils/futures.py index 3a9981ef..c6b68a44 100644 --- a/mode/utils/futures.py +++ b/mode/utils/futures.py @@ -1,4 +1,5 @@ """Async I/O Future utilities.""" + import asyncio from inspect import isawaitable from typing import Any, Callable, Optional, Set, Type diff --git a/mode/utils/graphs/formatter.py b/mode/utils/graphs/formatter.py index be553840..853a2b03 100644 --- a/mode/utils/graphs/formatter.py +++ b/mode/utils/graphs/formatter.py @@ -1,4 +1,5 @@ """Formatting graphs.""" + from typing import Any, Mapping from mode.utils.objects import label diff --git a/mode/utils/graphs/graph.py b/mode/utils/graphs/graph.py index ec943695..cb4aba71 100644 --- a/mode/utils/graphs/graph.py +++ b/mode/utils/graphs/graph.py @@ -1,4 +1,5 @@ """Data structure: Dependency graph.""" + from functools import partial from typing import ( IO, diff --git a/mode/utils/imports.py b/mode/utils/imports.py index 8a2c4365..1607dd47 100644 --- a/mode/utils/imports.py +++ b/mode/utils/imports.py @@ -1,4 +1,5 @@ """Importing utilities.""" + import importlib import os import sys diff --git a/mode/utils/locks.py b/mode/utils/locks.py index eff7e046..9554ab8f 100644 --- a/mode/utils/locks.py +++ b/mode/utils/locks.py @@ -4,6 +4,7 @@ which makes them unsuitable for use in programs that don't want to pass the loop around. """ + import asyncio from collections import deque from typing import Optional diff --git a/mode/utils/logging.py b/mode/utils/logging.py index bf6e93d4..e9082b34 100644 --- a/mode/utils/logging.py +++ b/mode/utils/logging.py @@ -1,4 +1,5 @@ """Logging utilities.""" + import abc import asyncio import logging @@ -71,9 +72,11 @@ HAS_STACKLEVEL = sys.version_info >= (3, 8) DEVLOG: bool = bool(os.environ.get("DEVLOG", "")) -DEFAULT_FORMAT: str = """ +DEFAULT_FORMAT: str = ( + """ [%(asctime)s] [%(process)s] [%(levelname)s]: %(message)s %(extra)s """.strip() +) DEFAULT_COLOR_FORMAT = """ [%(asctime)s] [%(process)s] [%(levelname)s] %(log_color)s%(message)s %(extra)s @@ -158,8 +161,7 @@ def get_logger(name: str) -> Logger: class HasLog(Protocol): @abc.abstractmethod - def log(self, severity: int, message: str, *args: Any, **kwargs: Any) -> None: - ... + def log(self, severity: int, message: str, *args: Any, **kwargs: Any) -> None: ... if typing.TYPE_CHECKING: @@ -870,8 +872,7 @@ def line_buffering(self) -> bool: def newlines(self) -> bool: return False - def flush(self) -> None: - ... + def flush(self) -> None: ... @property def mode(self) -> str: @@ -935,8 +936,7 @@ def __exit__( exc_type: Type[BaseException] = None, exc_val: BaseException = None, exc_tb: TracebackType = None, - ) -> Optional[bool]: - ... + ) -> Optional[bool]: ... @contextmanager diff --git a/mode/utils/loops.py b/mode/utils/loops.py index 2790cd13..bc41a006 100644 --- a/mode/utils/loops.py +++ b/mode/utils/loops.py @@ -1,4 +1,5 @@ """Event loop utilities.""" + import asyncio from typing import Any, Callable diff --git a/mode/utils/mocks.py b/mode/utils/mocks.py index c8778053..bcc06c7b 100644 --- a/mode/utils/mocks.py +++ b/mode/utils/mocks.py @@ -1,4 +1,5 @@ """Mocking and testing utilities.""" + import builtins import sys import types diff --git a/mode/utils/objects.py b/mode/utils/objects.py index ab39f670..c89d6c92 100644 --- a/mode/utils/objects.py +++ b/mode/utils/objects.py @@ -1,4 +1,5 @@ """Object utilities.""" + import abc import collections.abc import sys @@ -69,8 +70,7 @@ class ForwardRef: # noqa __forward_value__: Type __forward_code__: Any - def __init__(self, arg: str, is_argument: bool = True) -> None: - ... + def __init__(self, arg: str, is_argument: bool = True) -> None: ... else: try: @@ -114,8 +114,7 @@ def __init_subclass__( super().__init__(*args, **kwargs) @typing.no_type_check # type: ignore - class _UsingKwargsInNew(_InitSubclassCheck, ident=909): - ... + class _UsingKwargsInNew(_InitSubclassCheck, ident=909): ... except TypeError: abc_compatible_with_init_subclass = False diff --git a/mode/utils/queues.py b/mode/utils/queues.py index c78f19e9..970bb5b8 100644 --- a/mode/utils/queues.py +++ b/mode/utils/queues.py @@ -1,4 +1,5 @@ """Queue utilities - variations of :class:`asyncio.Queue`.""" + import asyncio import math import typing @@ -144,11 +145,9 @@ def in_pressure_high_state(self, callback: Callable) -> bool: return True return False - def on_pressure_high(self) -> None: - ... + def on_pressure_high(self) -> None: ... - def on_pressure_drop(self) -> None: - ... + def on_pressure_drop(self) -> None: ... def maybe_endorse_pressure_drop(self) -> None: pending = self._pending_pressure_drop_callbacks diff --git a/mode/utils/text.py b/mode/utils/text.py index 35005589..7871b844 100644 --- a/mode/utils/text.py +++ b/mode/utils/text.py @@ -1,4 +1,5 @@ """Text and string manipulation utilities.""" + from difflib import SequenceMatcher from typing import IO, AnyStr, Iterable, Iterator, NamedTuple, Optional diff --git a/mode/utils/times.py b/mode/utils/times.py index 87e113bb..6be1053e 100644 --- a/mode/utils/times.py +++ b/mode/utils/times.py @@ -1,4 +1,5 @@ """Time, date and timezone related utilities.""" + import abc import asyncio import sys @@ -121,21 +122,17 @@ def __init__( self._tokens = self.capacity self.__post_init__() - def __post_init__(self) -> None: - ... + def __post_init__(self) -> None: ... @abc.abstractmethod - def pour(self, tokens: int = 1) -> bool: - ... + def pour(self, tokens: int = 1) -> bool: ... @abc.abstractmethod - def expected_time(self, tokens: int = 1) -> float: - ... + def expected_time(self, tokens: int = 1) -> float: ... @property @abc.abstractmethod - def tokens(self) -> float: - ... + def tokens(self) -> float: ... @property def fill_rate(self) -> float: diff --git a/mode/utils/tracebacks.py b/mode/utils/tracebacks.py index 96348405..6894477c 100644 --- a/mode/utils/tracebacks.py +++ b/mode/utils/tracebacks.py @@ -1,4 +1,5 @@ """Traceback utilities.""" + import asyncio import inspect import io diff --git a/mode/utils/trees.py b/mode/utils/trees.py index b3d58efc..5a660b35 100644 --- a/mode/utils/trees.py +++ b/mode/utils/trees.py @@ -1,4 +1,5 @@ """Data structure: Trees.""" + from contextlib import suppress from typing import Any, Iterator, List, Optional, TypeVar, Union, cast diff --git a/mode/utils/types/graphs.py b/mode/utils/types/graphs.py index 37feb882..afa4a896 100644 --- a/mode/utils/types/graphs.py +++ b/mode/utils/types/graphs.py @@ -1,4 +1,5 @@ """Type classes for :mod:`mode.utils.graphs`.""" + import abc from typing import ( IO, @@ -34,54 +35,44 @@ def __init__( indent: int = 0, inw: str = " " * 4, **scheme: Any - ) -> None: - ... + ) -> None: ... @abc.abstractmethod - def attr(self, name: str, value: Any) -> str: - ... + def attr(self, name: str, value: Any) -> str: ... @abc.abstractmethod - def attrs(self, d: Mapping = None, scheme: Mapping = None) -> str: - ... + def attrs(self, d: Mapping = None, scheme: Mapping = None) -> str: ... @abc.abstractmethod - def head(self, **attrs: Any) -> str: - ... + def head(self, **attrs: Any) -> str: ... @abc.abstractmethod - def tail(self) -> str: - ... + def tail(self) -> str: ... @abc.abstractmethod - def label(self, obj: _T) -> str: - ... + def label(self, obj: _T) -> str: ... @abc.abstractmethod - def node(self, obj: _T, **attrs: Any) -> str: - ... + def node(self, obj: _T, **attrs: Any) -> str: ... @abc.abstractmethod - def terminal_node(self, obj: _T, **attrs: Any) -> str: - ... + def terminal_node(self, obj: _T, **attrs: Any) -> str: ... @abc.abstractmethod - def edge(self, a: _T, b: _T, **attrs: Any) -> str: - ... + def edge(self, a: _T, b: _T, **attrs: Any) -> str: ... @abc.abstractmethod - def FMT(self, fmt: str, *args: Any, **kwargs: Any) -> str: - ... + def FMT(self, fmt: str, *args: Any, **kwargs: Any) -> str: ... @abc.abstractmethod def draw_edge( self, a: _T, b: _T, scheme: Mapping = None, attrs: Mapping = None - ) -> str: - ... + ) -> str: ... @abc.abstractmethod - def draw_node(self, obj: _T, scheme: Mapping = None, attrs: Mapping = None) -> str: - ... + def draw_node( + self, obj: _T, scheme: Mapping = None, attrs: Mapping = None + ) -> str: ... class DependencyGraphT(Generic[_T], Mapping[_T, _T]): @@ -92,37 +83,28 @@ class DependencyGraphT(Generic[_T], Mapping[_T, _T]): @abc.abstractmethod def __init__( self, it: Iterable[_T] = None, formatter: GraphFormatterT[_T] = None - ) -> None: - ... + ) -> None: ... @abc.abstractmethod - def add_arc(self, obj: _T) -> None: - ... + def add_arc(self, obj: _T) -> None: ... @abc.abstractmethod - def add_edge(self, A: _T, B: _T) -> None: - ... + def add_edge(self, A: _T, B: _T) -> None: ... @abc.abstractmethod - def connect(self, graph: "DependencyGraphT") -> None: - ... + def connect(self, graph: "DependencyGraphT") -> None: ... @abc.abstractmethod - def topsort(self) -> Sequence: - ... + def topsort(self) -> Sequence: ... @abc.abstractmethod - def valency_of(self, obj: _T) -> int: - ... + def valency_of(self, obj: _T) -> int: ... @abc.abstractmethod - def update(self, it: Iterable) -> None: - ... + def update(self, it: Iterable) -> None: ... @abc.abstractmethod - def edges(self) -> Iterable: - ... + def edges(self) -> Iterable: ... @abc.abstractmethod - def to_dot(self, fh: IO, *, formatter: GraphFormatterT[_T] = None) -> None: - ... + def to_dot(self, fh: IO, *, formatter: GraphFormatterT[_T] = None) -> None: ... diff --git a/mode/utils/types/trees.py b/mode/utils/types/trees.py index da08edef..c2fc0f3b 100644 --- a/mode/utils/types/trees.py +++ b/mode/utils/types/trees.py @@ -1,4 +1,5 @@ """Type classes for :mod:`mode.utils.trees`.""" + import abc from typing import Any, Generic, Iterator, List, Optional, TypeVar, Union @@ -17,69 +18,53 @@ class NodeT(Generic[_T]): @classmethod @abc.abstractmethod - def _new_node(cls, data: _T, **kwargs: Any) -> "NodeT": - ... + def _new_node(cls, data: _T, **kwargs: Any) -> "NodeT": ... @abc.abstractmethod - def new(self, data: _T) -> "NodeT": - ... + def new(self, data: _T) -> "NodeT": ... @abc.abstractmethod - def add(self, data: Union[_T, "NodeT[_T]"]) -> None: - ... + def add(self, data: Union[_T, "NodeT[_T]"]) -> None: ... @abc.abstractmethod - def add_deduplicate(self, data: Union[_T, "NodeT[_T]"]) -> None: - ... + def add_deduplicate(self, data: Union[_T, "NodeT[_T]"]) -> None: ... @abc.abstractmethod - def discard(self, data: _T) -> None: - ... + def discard(self, data: _T) -> None: ... @abc.abstractmethod - def reattach(self, parent: "NodeT") -> "NodeT": - ... + def reattach(self, parent: "NodeT") -> "NodeT": ... @abc.abstractmethod - def traverse(self) -> Iterator["NodeT"]: - ... + def traverse(self) -> Iterator["NodeT"]: ... @abc.abstractmethod - def walk(self) -> Iterator["NodeT"]: - ... + def walk(self) -> Iterator["NodeT"]: ... @abc.abstractmethod - def as_graph(self) -> DependencyGraphT: - ... + def as_graph(self) -> DependencyGraphT: ... @abc.abstractmethod - def detach(self, parent: "NodeT") -> "NodeT": - ... + def detach(self, parent: "NodeT") -> "NodeT": ... @property @abc.abstractmethod - def parent(self) -> Optional["NodeT"]: - ... + def parent(self) -> Optional["NodeT"]: ... @parent.setter - def parent(self, node: "NodeT") -> None: - ... + def parent(self, node: "NodeT") -> None: ... @property @abc.abstractmethod - def root(self) -> Optional["NodeT"]: - ... + def root(self) -> Optional["NodeT"]: ... @root.setter - def root(self, node: "NodeT") -> None: - ... + def root(self, node: "NodeT") -> None: ... @property @abc.abstractmethod - def depth(self) -> int: - ... + def depth(self) -> int: ... @property @abc.abstractmethod - def path(self) -> str: - ... + def path(self) -> str: ... diff --git a/mode/utils/typing.py b/mode/utils/typing.py index 36b874d6..0b2fa2cc 100644 --- a/mode/utils/typing.py +++ b/mode/utils/typing.py @@ -1,4 +1,5 @@ """Backport of :mod:`typing` additions in Python 3.7.""" + # pragma: no cover import typing diff --git a/mode/worker.py b/mode/worker.py index 1d98ab6c..d046a677 100644 --- a/mode/worker.py +++ b/mode/worker.py @@ -3,6 +3,7 @@ Workers add signal handling, logging, and other things required to start and manage services in a process environment. """ + import asyncio import logging as _logging import os @@ -40,8 +41,7 @@ from .debug import BlockingDetector else: - class BlockingDetector: - ... # noqa + class BlockingDetector: ... # noqa __all__ = ["Worker"] @@ -181,8 +181,7 @@ async def default_on_first_start(self) -> None: await self._add_monitor() self.install_signal_handlers() - async def on_execute(self) -> None: - ... + async def on_execute(self) -> None: ... def _setup_logging(self) -> None: _loglevel: int = 0 @@ -209,8 +208,7 @@ def _setup_logging(self) -> None: def _redirect_stdouts(self) -> None: self.add_context(logging.redirect_stdouts(severity=self.redirect_stdouts_level)) - def on_setup_root_logger(self, logger: Logger, level: int) -> None: - ... + def on_setup_root_logger(self, logger: Logger, level: int) -> None: ... async def maybe_start_blockdetection(self) -> None: if self.debug: @@ -291,8 +289,7 @@ def execute_from_commandline(self) -> NoReturn: # for mypy NoReturn raise SystemExit(EX_OK) # pragma: no cover - def on_worker_shutdown(self) -> None: - ... + def on_worker_shutdown(self) -> None: ... def stop_and_shutdown(self) -> None: if self._signal_stop_future and not self._signal_stop_future.done(): diff --git a/requirements/test.txt b/requirements/test.txt index 870a9d77..32522f82 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -4,7 +4,7 @@ mock; python_version<'3.8' # backport that contains AsyncMock class, includes m hypothesis>=3.31 freezegun>=0.3.11 pytest-aiofiles>=0.2.0 -pytest-asyncio>=0.8 +pytest-asyncio==0.21.1 pytest-base-url>=1.4.1 pytest-forked pytest-openfiles>=0.2.0 diff --git a/t/functional/test_service.py b/t/functional/test_service.py index 15a3d57e..d40a057b 100644 --- a/t/functional/test_service.py +++ b/t/functional/test_service.py @@ -9,8 +9,7 @@ from mode.utils.locks import Event -class X(mode.Service): - ... +class X(mode.Service): ... class Context(ContextManager): @@ -276,8 +275,7 @@ async def winner(): fut1.cancel() -class MundaneLogsDefault(mode.Service): - ... +class MundaneLogsDefault(mode.Service): ... class MundaneLogsDebug(mode.Service): diff --git a/t/functional/test_signals.py b/t/functional/test_signals.py index 338439b8..a9e1c672 100644 --- a/t/functional/test_signals.py +++ b/t/functional/test_signals.py @@ -17,8 +17,7 @@ def __init__(self): self.on_stopped = self.on_stopped.with_default_sender(self) -class Y(X): - ... +class Y(X): ... class SyncX: diff --git a/t/functional/test_supervisors.py b/t/functional/test_supervisors.py index d0529420..bb1d01e8 100644 --- a/t/functional/test_supervisors.py +++ b/t/functional/test_supervisors.py @@ -30,8 +30,7 @@ async def restart(self) -> None: await super().restart() -class X(StatService): - ... +class X(StatService): ... class Y(StatService): @@ -42,8 +41,7 @@ def __post_init__(self) -> None: self.add_dependency(self.x) -class Z(StatService): - ... +class Z(StatService): ... class SupervisorTest: diff --git a/t/functional/utils/test_collections.py b/t/functional/utils/test_collections.py index 132a65d9..d4c11fe9 100644 --- a/t/functional/utils/test_collections.py +++ b/t/functional/utils/test_collections.py @@ -587,8 +587,7 @@ def test_pickle(self, d): class test_AttributeDictMixin: @pytest.fixture() def d(self): - class X(dict, AttributeDictMixin): - ... + class X(dict, AttributeDictMixin): ... return X() diff --git a/t/unit/test_locals.py b/t/unit/test_locals.py index 2c3bd151..ba91e9e1 100644 --- a/t/unit/test_locals.py +++ b/t/unit/test_locals.py @@ -106,8 +106,7 @@ def __dir__(self): assert dir(y) == [] def test_qualname(self): - class X: - ... + class X: ... x = Proxy(lambda: X) assert x.__qualname__ == X.__qualname__ @@ -623,8 +622,7 @@ async def test_anext(self, *, s): class test_AsyncGeneratorProxy(test_AsyncIteratorProxy): # Note: Inherits all test cases from test_AsyncIteratorProxy - class Double(Exception): - ... # tells coro to double multiplier + class Double(Exception): ... # tells coro to double multiplier @pytest.fixture() def s(self, *, orig): @@ -668,8 +666,7 @@ async def test_coro(self, *, coro): class test_CoroutineProxy: # Note: Inherits all test cases from test_AsyncIteratorProxy - class Double(Exception): - ... # tells coro to double multiplier + class Double(Exception): ... # tells coro to double multiplier def corogen(self): multiplier = 2 @@ -710,12 +707,10 @@ def test_await(self): def test_Proxy_from_source(): class AbstractSource(abc.ABC): @abc.abstractmethod - def add(self, arg): - ... + def add(self, arg): ... @abc.abstractmethod - def mul(self, arg): - ... + def mul(self, arg): ... class ConcreteSource(AbstractSource): def __init__(self, value): @@ -745,12 +740,10 @@ class ProxySource(Proxy[AbstractSource]): def test_Proxy_from_source__py37_class_argument(): class AbstractSource(abc.ABC): @abc.abstractmethod - def add(self, arg): - ... + def add(self, arg): ... @abc.abstractmethod - def mul(self, arg): - ... + def mul(self, arg): ... class ConcreteSource(AbstractSource): def __init__(self, value): @@ -762,8 +755,7 @@ def add(self, arg): def mul(self, arg): return self.value * arg - class ProxySource(Proxy[AbstractSource], source=AbstractSource): - ... + class ProxySource(Proxy[AbstractSource], source=AbstractSource): ... on_final_mock = Mock() on_final = Proxy(on_final_mock) @@ -777,8 +769,7 @@ class ProxySource(Proxy[AbstractSource], source=AbstractSource): def test_Proxy_from_source__no_ABCMeta(): - class Source: - ... + class Source: ... with pytest.raises(TypeError): @@ -787,8 +778,7 @@ class ProxySource(Proxy[Source]): def test_Proxy_from_source__no_abstractmethods(): - class Source(abc.ABC): - ... + class Source(abc.ABC): ... class ProxySource(Proxy[Source]): __proxy_source__ = Source diff --git a/t/unit/test_services.py b/t/unit/test_services.py index cf05ba6e..62dd770b 100644 --- a/t/unit/test_services.py +++ b/t/unit/test_services.py @@ -530,8 +530,7 @@ def test_get_set_loop(self, *, service): assert service.loop is m def test__get_tasks__no_tasks(self, *, service): - class X(type(service)): - ... + class X(type(service)): ... X._tasks = [] assert list(X()._get_tasks()) == [] diff --git a/t/unit/utils/test_objects.py b/t/unit/utils/test_objects.py index 024157c0..9ecc1e20 100644 --- a/t/unit/utils/test_objects.py +++ b/t/unit/utils/test_objects.py @@ -56,20 +56,16 @@ EXTRA_GENERIC_INHERITS_FROM = [abc.ABC] -class D(Service): - ... +class D(Service): ... -class C(D): - ... +class C(D): ... -class B(C): - ... +class B(C): ... -class A(B): - ... +class A(B): ... @pytest.mark.parametrize( @@ -132,8 +128,7 @@ def test_KeywordReduce(): def test_qualname_object(): - class X: - ... + class X: ... assert qualname("foo") == "builtins.str" assert qualname(str) == "builtins.str" @@ -143,8 +138,7 @@ class X: def test_shortname_object(): - class X: - ... + class X: ... assert shortname("foo") == "builtins.str" assert shortname(str) == "builtins.str" @@ -154,14 +148,12 @@ class X: def test_canoname(): - class X: - ... + class X: ... X.__module__ = "__main__" x = X() - class Y: - ... + class Y: ... y = Y() @@ -182,14 +174,12 @@ class Y: def test_canonshortname(): - class X: - ... + class X: ... X.__module__ = "__main__" x = X() - class Y: - ... + class Y: ... y = Y() @@ -272,8 +262,7 @@ class X: def test_annotations__no_local_ns_raises(): - class Bar: - ... + class Bar: ... class X: bar: "Bar" @@ -407,8 +396,7 @@ def test_guess_polymorphic_type(input, expected): def test_guess_polymorphic_type__not_generic(): - class X: - ... + class X: ... with pytest.raises(TypeError): guess_polymorphic_type(str)