From f9fa81e5fcb3d7996edff08deb0d770b9f03e56b Mon Sep 17 00:00:00 2001 From: Dag Brattli Date: Sat, 25 May 2024 21:36:17 +0200 Subject: [PATCH] Upgrade pyright and fix typing errors --- .pre-commit-config.yaml | 4 ++-- aioreactive/__init__.py | 11 ++++++----- aioreactive/combine.py | 2 +- aioreactive/create.py | 2 +- aioreactive/msg.py | 1 + aioreactive/testing/__init__.py | 1 + pyproject.toml | 10 +++++----- tests/test_single_stream.py | 2 -- tests/test_stream.py | 1 - 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1410945..4a3e61a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: - id: ruff-format args: [--check] repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.13 + rev: v0.4.5 - hooks: - id: pyright name: pyright @@ -14,5 +14,5 @@ repos: language: node pass_filenames: false types: [python] - additional_dependencies: ["pyright@1.1.344"] + additional_dependencies: ["pyright@1.1.364"] repo: local diff --git a/aioreactive/__init__.py b/aioreactive/__init__.py index a905776..5a059b5 100644 --- a/aioreactive/__init__.py +++ b/aioreactive/__init__.py @@ -12,6 +12,7 @@ >>> ... """ + from __future__ import annotations from collections.abc import AsyncIterable, Awaitable, Callable, Iterable @@ -120,13 +121,13 @@ def __getitem__(self, key: slice | int) -> AsyncRx[_TSource]: return AsyncRx(pipe(self, _slice(start, stop, step or 1))) - @classmethod - def create(cls, source: AsyncObservable[_TSource]) -> AsyncRx[_TSource]: + @staticmethod + def create(source: AsyncObservable[_TResult]) -> AsyncRx[_TResult]: """Create `AsyncChainedObservable`. Helper method for creating an `AsyncChainedObservable`. """ - return cls(source) + return AsyncRx(source) @classmethod def empty(cls) -> AsyncRx[_TSource]: @@ -136,8 +137,8 @@ def empty(cls) -> AsyncRx[_TSource]: def from_iterable(cls, iter: Iterable[_TSource]) -> AsyncRx[_TSource]: return AsyncRx(from_iterable(iter)) - @classmethod - def from_async_iterable(cls, iter: AsyncIterable[_TSource]) -> AsyncObservable[_TSource]: + @staticmethod + def from_async_iterable(iter: AsyncIterable[_TResult]) -> AsyncObservable[_TResult]: """Convert an async iterable to an async observable stream. Example: diff --git a/aioreactive/combine.py b/aioreactive/combine.py index 5c2bf9b..7cdd42a 100644 --- a/aioreactive/combine.py +++ b/aioreactive/combine.py @@ -88,7 +88,7 @@ async def update(msg: Msg[_TSource], model: Model[_TSource]) -> Model[_TSource]: subscriptions=model.subscriptions.add(model.key, inner), key=Key(model.key + 1), ) - lst = Block.singleton(xs) + lst = Block[AsyncObservable[_TSource]].singleton(xs) return model.replace(queue=model.queue.append(lst)) case Msg(tag="inner_completed", inner_completed=key): subscriptions = model.subscriptions.remove(key) diff --git a/aioreactive/create.py b/aioreactive/create.py index 4658a6c..ea0f4ef 100644 --- a/aioreactive/create.py +++ b/aioreactive/create.py @@ -100,7 +100,7 @@ async def worker() -> None: try: task = asyncio.create_task(worker()) except Exception as ex: - log.debug("FromIterable:worker(), Exception: %s" % ex) + log.debug(f"FromIterable:worker(), Exception: {ex}") await observer.athrow(ex) else: tasks.add(task) diff --git a/aioreactive/msg.py b/aioreactive/msg.py index dec4858..ed78120 100644 --- a/aioreactive/msg.py +++ b/aioreactive/msg.py @@ -1,4 +1,5 @@ """Internal messages used by mailbox processors. Do not import or use.""" + from typing import Generic, Literal, NewType, TypeVar from expression import case, tag, tagged_union diff --git a/aioreactive/testing/__init__.py b/aioreactive/testing/__init__.py index abda9d2..e10d281 100644 --- a/aioreactive/testing/__init__.py +++ b/aioreactive/testing/__init__.py @@ -2,6 +2,7 @@ Contains utilities for unit testing async observables. """ + from .observer import AsyncTestObserver from .subject import AsyncTestSingleSubject, AsyncTestSubject from .utils import ca diff --git a/pyproject.toml b/pyproject.toml index 89893ce..15324b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,15 +40,15 @@ line-length = 120 # D100: Missing docstring in public module # D104: Missing docstring in public package # D105: Missing docstring in magic method -ignore = ["D100", "D101", "D102", "D103", "D105", "D107"] -target-version = "py310" -select = ["D", "E", "W", "F", "I", "T", "RUF", "TID", "UP"] +lint.ignore = ["D100", "D101", "D102", "D103", "D105", "D107"] +lint.select = ["D", "E", "W", "F", "I", "T", "RUF", "TID", "UP"] exclude = ["tests", "docs", "examples"] +target-version = "py310" -[tool.ruff.pydocstyle] +[tool.ruff.lint.pydocstyle] convention = "google" -[tool.ruff.isort] +[tool.ruff.lint.isort] lines-after-imports = 2 known-third-party = ["pytest"] diff --git a/tests/test_single_stream.py b/tests/test_single_stream.py index 3c71a7b..262f538 100644 --- a/tests/test_single_stream.py +++ b/tests/test_single_stream.py @@ -124,7 +124,6 @@ def mapper(value: int) -> int: sink = AsyncTestObserver(asend) async with await ys.subscribe_async(sink) as sub: - await xs.asend_later(1, 10) with pytest.raises(ObjectDisposedException): @@ -149,7 +148,6 @@ async def mapper(value: int) -> int: sink: AsyncObserver[int] = AsyncTestObserver() async with await ys.subscribe_async(sink) as sub: - await xs.asend_later(1, 10) with pytest.raises(ObjectDisposedException): await xs.asend_later(1, 20) diff --git a/tests/test_stream.py b/tests/test_stream.py index 778ddc3..a068974 100644 --- a/tests/test_stream.py +++ b/tests/test_stream.py @@ -146,7 +146,6 @@ def mapper(value: int) -> int: obv: AsyncTestObserver[int] = AsyncTestObserver() async with await ys.subscribe_async(obv) as subscription: - await xs.asend_later(100, 10) await xs.asend_later(100, 20) await xs.asend_later(100, 30)