From 5d8b06c7f20dfd69ded4e7b349121818a4d35011 Mon Sep 17 00:00:00 2001 From: Dag Brattli Date: Sat, 18 Jun 2022 09:11:40 +0200 Subject: [PATCH] fix: typing fixes for Pyright 254 --- .pre-commit-config.yaml | 2 +- reactivex/internal/utils.py | 2 +- reactivex/observable/fromfuture.py | 2 +- reactivex/operators/__init__.py | 2 +- reactivex/operators/_groupbyuntil.py | 10 +++++----- reactivex/operators/_max.py | 4 ++-- reactivex/operators/_min.py | 4 ++-- reactivex/operators/_reduce.py | 2 +- reactivex/operators/_throttlefirst.py | 2 +- reactivex/scheduler/mainloop/qtscheduler.py | 3 +-- 10 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c40878545..463b263d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,7 +26,7 @@ repos: language: node pass_filenames: false types: [python] - additional_dependencies: ["pyright@1.1.235"] + additional_dependencies: ["pyright@1.1.254"] repo: local - hooks: - id: mypy diff --git a/reactivex/internal/utils.py b/reactivex/internal/utils.py index dbdcbe62e..109717d84 100644 --- a/reactivex/internal/utils.py +++ b/reactivex/internal/utils.py @@ -45,7 +45,7 @@ def alias(name: str, doc: str, fun: Callable[_P, _T]) -> Callable[_P, _T]: alias_.__kwdefaults__ = _fun.__kwdefaults__ alias_.__doc__ = doc alias_.__annotations__ = _fun.__annotations__ - return alias_ + return cast(Callable[_P, _T], alias_) class NotSet: diff --git a/reactivex/observable/fromfuture.py b/reactivex/observable/fromfuture.py index 16c01c02b..caabebf55 100644 --- a/reactivex/observable/fromfuture.py +++ b/reactivex/observable/fromfuture.py @@ -38,7 +38,7 @@ def done(future: "Future[_T]") -> None: future.add_done_callback(done) def dispose() -> None: - if future and future.cancel: + if future: future.cancel() return Disposable(dispose) diff --git a/reactivex/operators/__init__.py b/reactivex/operators/__init__.py index 5d2258309..0851b22fd 100644 --- a/reactivex/operators/__init__.py +++ b/reactivex/operators/__init__.py @@ -2559,7 +2559,7 @@ def scan( @overload def scan( - accumulator: Accumulator[_TState, _T], seed: _TState + accumulator: Accumulator[_TState, _T], seed: Union[_TState, Type[NotSet]] ) -> Callable[[Observable[_T]], Observable[_TState]]: ... diff --git a/reactivex/operators/_groupbyuntil.py b/reactivex/operators/_groupbyuntil.py index eb9d8afd7..39100c0f8 100644 --- a/reactivex/operators/_groupbyuntil.py +++ b/reactivex/operators/_groupbyuntil.py @@ -119,7 +119,7 @@ def on_next(x: _T) -> None: sad = SingleAssignmentDisposable() group_disposable.add(sad) - def expire(): + def expire() -> None: if writers[key]: del writers[key] writer.on_completed() @@ -134,12 +134,12 @@ def on_error(exn: Exception) -> None: wrt.on_error(exn) observer.on_error(exn) - def on_completed(): + def on_completed() -> None: expire() - sad.disposable = duration.pipe(ops.take(1)).subscribe( - on_next, on_error, on_completed, scheduler=scheduler - ) + sad.disposable = duration.pipe( + ops.take(1), + ).subscribe(on_next, on_error, on_completed, scheduler=scheduler) try: element = element_mapper_(x) diff --git a/reactivex/operators/_max.py b/reactivex/operators/_max.py index 32db72993..287d5fb7c 100644 --- a/reactivex/operators/_max.py +++ b/reactivex/operators/_max.py @@ -1,4 +1,4 @@ -from typing import Callable, Optional, TypeVar +from typing import Callable, Optional, TypeVar, cast from reactivex import Observable, compose from reactivex import operators as ops @@ -29,7 +29,7 @@ def max_( maximum element in the source sequence. """ return compose( - ops.max_by(identity, comparer), + ops.max_by(cast(Callable[[_T], _T], identity), comparer), ops.map(first_only), ) diff --git a/reactivex/operators/_min.py b/reactivex/operators/_min.py index 64b11b030..85a89c8d6 100644 --- a/reactivex/operators/_min.py +++ b/reactivex/operators/_min.py @@ -1,4 +1,4 @@ -from typing import Callable, List, Optional, TypeVar +from typing import Callable, List, Optional, TypeVar, cast from reactivex import Observable, compose from reactivex import operators as ops @@ -36,7 +36,7 @@ def min_( with the minimum element in the source sequence. """ return compose( - ops.min_by(identity, comparer), + ops.min_by(cast(Callable[[_T], _T], identity), comparer), ops.map(first_only), ) diff --git a/reactivex/operators/_reduce.py b/reactivex/operators/_reduce.py index 7c244adb8..8238ea964 100644 --- a/reactivex/operators/_reduce.py +++ b/reactivex/operators/_reduce.py @@ -43,7 +43,7 @@ def reduce_( ) return compose( - ops.scan(accumulator), + ops.scan(cast(Accumulator[_T, _T], accumulator)), ops.last(), ) diff --git a/reactivex/operators/_throttlefirst.py b/reactivex/operators/_throttlefirst.py index e4139eaa1..58fec06ac 100644 --- a/reactivex/operators/_throttlefirst.py +++ b/reactivex/operators/_throttlefirst.py @@ -13,7 +13,7 @@ def throttle_first_( def throttle_first(source: Observable[_T]) -> Observable[_T]: """Returns an observable that emits only the first item emitted by the source Observable during sequential time windows of a - specifiedduration. + specified duration. Args: source: Source observable to throttle. diff --git a/reactivex/scheduler/mainloop/qtscheduler.py b/reactivex/scheduler/mainloop/qtscheduler.py index f16370e2b..bee0101b2 100644 --- a/reactivex/scheduler/mainloop/qtscheduler.py +++ b/reactivex/scheduler/mainloop/qtscheduler.py @@ -28,8 +28,7 @@ def __init__(self, qtcore: Any): """ super().__init__() self._qtcore = qtcore - timer_class: Any = self._qtcore.QTimer - self._periodic_timers: Set[timer_class] = set() + self._periodic_timers: Set[Any] = set() def schedule( self, action: typing.ScheduledAction[_TState], state: Optional[_TState] = None