Skip to content

Commit b5fb2ad

Browse files
committed
Fix type error in flat-map
1 parent 5b1ff9c commit b5fb2ad

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repos:
2626
language: node
2727
pass_filenames: false
2828
types: [python]
29-
additional_dependencies: ["pyright@1.1.227"]
29+
additional_dependencies: ["pyright@1.1.228"]
3030
repo: local
3131
- hooks:
3232
- id: mypy

reactivex/internal/concurrency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from threading import RLock, Thread
22
from typing import Any, Callable, TypeVar
3+
34
from typing_extensions import ParamSpec
45

56
from reactivex.typing import StartableTarget
67

7-
88
_T = TypeVar("_T")
99
_P = ParamSpec("_P")
1010

reactivex/internal/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from functools import update_wrapper
22
from types import FunctionType
33
from typing import TYPE_CHECKING, Any, Callable, Iterable, Optional, TypeVar, cast
4+
45
from typing_extensions import ParamSpec
6+
57
from reactivex import abc
68
from reactivex.disposable import CompositeDisposable
79
from reactivex.disposable.refcountdisposable import RefCountDisposable
@@ -38,7 +40,7 @@ def alias(name: str, doc: str, fun: Callable[_P, _T]) -> Callable[_P, _T]:
3840
_fun = cast(FunctionType, fun)
3941
args = (_fun.__code__, _fun.__globals__)
4042
kwargs = {"name": name, "argdefs": _fun.__defaults__, "closure": _fun.__closure__}
41-
alias_ = FunctionType(*args, **kwargs)
43+
alias_ = FunctionType(*args, **kwargs) # type: ignore
4244
alias_ = update_wrapper(alias_, _fun)
4345
alias_.__kwdefaults__ = _fun.__kwdefaults__
4446
alias_.__doc__ = doc

reactivex/operators/_flatmap.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from asyncio import Future
2-
from typing import Any, Callable, Iterable, Optional, TypeVar, Union, cast
2+
from typing import Any, Callable, Optional, TypeVar, Union, cast
33

44
from reactivex import Observable, from_, from_future
55
from reactivex import operators as ops
6+
from reactivex.internal.basic import identity
67
from reactivex.typing import Mapper, MapperIndexed
78

89
_T1 = TypeVar("_T1")
@@ -14,14 +15,16 @@ def _flat_map_internal(
1415
mapper: Optional[Mapper[_T1, Any]] = None,
1516
mapper_indexed: Optional[MapperIndexed[_T1, Any]] = None,
1617
) -> Observable[Any]:
17-
def projection(x: _T1, i: int):
18-
mapper_result = (
19-
mapper(x) if mapper else mapper_indexed(x, i) if mapper_indexed else None
18+
def projection(x: _T1, i: int) -> Observable[Any]:
19+
mapper_result: Any = (
20+
mapper(x)
21+
if mapper
22+
else mapper_indexed(x, i)
23+
if mapper_indexed
24+
else identity
2025
)
2126
if isinstance(mapper_result, Future):
2227
result: Observable[Any] = from_future(cast("Future[Any]", mapper_result))
23-
elif isinstance(mapper_result, Iterable):
24-
result = from_(mapper_result)
2528
elif isinstance(mapper_result, Observable):
2629
result = mapper_result
2730
else:

0 commit comments

Comments
 (0)