reactivex 4.1.0__py3-none-any.whl → 5.0.0a2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. reactivex/__init__.py +35 -39
  2. reactivex/_version.py +1 -1
  3. reactivex/abc/disposable.py +3 -4
  4. reactivex/abc/observable.py +13 -6
  5. reactivex/abc/observer.py +2 -1
  6. reactivex/abc/periodicscheduler.py +7 -6
  7. reactivex/abc/scheduler.py +10 -9
  8. reactivex/abc/subject.py +5 -5
  9. reactivex/disposable/compositedisposable.py +4 -4
  10. reactivex/disposable/disposable.py +1 -2
  11. reactivex/disposable/multipleassignmentdisposable.py +2 -3
  12. reactivex/disposable/refcountdisposable.py +1 -2
  13. reactivex/disposable/serialdisposable.py +4 -5
  14. reactivex/disposable/singleassignmentdisposable.py +3 -4
  15. reactivex/internal/__init__.py +2 -0
  16. reactivex/internal/basic.py +2 -2
  17. reactivex/internal/concurrency.py +2 -1
  18. reactivex/internal/curry.py +59 -0
  19. reactivex/internal/exceptions.py +7 -12
  20. reactivex/internal/priorityqueue.py +2 -2
  21. reactivex/internal/utils.py +3 -2
  22. reactivex/notification.py +22 -21
  23. reactivex/observable/case.py +5 -6
  24. reactivex/observable/catch.py +3 -2
  25. reactivex/observable/combinelatest.py +4 -5
  26. reactivex/observable/concat.py +3 -2
  27. reactivex/observable/connectableobservable.py +7 -7
  28. reactivex/observable/defer.py +4 -3
  29. reactivex/observable/empty.py +3 -4
  30. reactivex/observable/forkjoin.py +5 -5
  31. reactivex/observable/fromcallback.py +4 -3
  32. reactivex/observable/fromfuture.py +2 -2
  33. reactivex/observable/fromiterable.py +4 -3
  34. reactivex/observable/generate.py +2 -2
  35. reactivex/observable/generatewithrelativetime.py +4 -3
  36. reactivex/observable/groupedobservable.py +4 -4
  37. reactivex/observable/ifthen.py +3 -2
  38. reactivex/observable/interval.py +1 -4
  39. reactivex/observable/marbles.py +18 -17
  40. reactivex/observable/mixins/__init__.py +32 -0
  41. reactivex/observable/mixins/combination.py +481 -0
  42. reactivex/observable/mixins/conditional.py +135 -0
  43. reactivex/observable/mixins/error_handling.py +130 -0
  44. reactivex/observable/mixins/filtering.py +1119 -0
  45. reactivex/observable/mixins/mathematical.py +277 -0
  46. reactivex/observable/mixins/multicasting.py +306 -0
  47. reactivex/observable/mixins/testing.py +193 -0
  48. reactivex/observable/mixins/time_based.py +209 -0
  49. reactivex/observable/mixins/transformation.py +632 -0
  50. reactivex/observable/mixins/utility.py +811 -0
  51. reactivex/observable/mixins/windowing.py +688 -0
  52. reactivex/observable/never.py +2 -2
  53. reactivex/observable/observable.py +72 -25
  54. reactivex/observable/onerrorresumenext.py +7 -6
  55. reactivex/observable/range.py +6 -6
  56. reactivex/observable/repeat.py +2 -2
  57. reactivex/observable/returnvalue.py +6 -5
  58. reactivex/observable/start.py +3 -2
  59. reactivex/observable/startasync.py +2 -1
  60. reactivex/observable/throw.py +3 -3
  61. reactivex/observable/timer.py +12 -12
  62. reactivex/observable/toasync.py +3 -2
  63. reactivex/observable/using.py +5 -4
  64. reactivex/observable/withlatestfrom.py +4 -5
  65. reactivex/observable/zip.py +7 -6
  66. reactivex/observer/autodetachobserver.py +4 -4
  67. reactivex/observer/observer.py +5 -4
  68. reactivex/observer/scheduledobserver.py +2 -2
  69. reactivex/operators/__init__.py +162 -208
  70. reactivex/operators/_all.py +23 -6
  71. reactivex/operators/_amb.py +88 -75
  72. reactivex/operators/_asobservable.py +20 -17
  73. reactivex/operators/_average.py +48 -45
  74. reactivex/operators/_buffer.py +81 -35
  75. reactivex/operators/_bufferwithtime.py +29 -9
  76. reactivex/operators/_bufferwithtimeorcount.py +27 -8
  77. reactivex/operators/_catch.py +33 -32
  78. reactivex/operators/_combinelatest.py +28 -20
  79. reactivex/operators/_concat.py +16 -13
  80. reactivex/operators/_contains.py +25 -6
  81. reactivex/operators/_count.py +24 -8
  82. reactivex/operators/_debounce.py +141 -138
  83. reactivex/operators/_defaultifempty.py +45 -42
  84. reactivex/operators/_delay.py +24 -23
  85. reactivex/operators/_delaysubscription.py +23 -21
  86. reactivex/operators/_delaywithmapper.py +10 -11
  87. reactivex/operators/_dematerialize.py +25 -21
  88. reactivex/operators/_distinct.py +50 -46
  89. reactivex/operators/_distinctuntilchanged.py +60 -57
  90. reactivex/operators/_do.py +123 -116
  91. reactivex/operators/_dowhile.py +3 -2
  92. reactivex/operators/_elementatordefault.py +57 -33
  93. reactivex/operators/_exclusive.py +59 -53
  94. reactivex/operators/_expand.py +82 -77
  95. reactivex/operators/_filter.py +63 -68
  96. reactivex/operators/_finallyaction.py +3 -2
  97. reactivex/operators/_find.py +49 -32
  98. reactivex/operators/_first.py +18 -11
  99. reactivex/operators/_firstordefault.py +5 -4
  100. reactivex/operators/_flatmap.py +89 -83
  101. reactivex/operators/_forkjoin.py +23 -18
  102. reactivex/operators/_groupby.py +27 -6
  103. reactivex/operators/_groupbyuntil.py +8 -5
  104. reactivex/operators/_groupjoin.py +7 -6
  105. reactivex/operators/_ignoreelements.py +20 -15
  106. reactivex/operators/_isempty.py +15 -4
  107. reactivex/operators/_join.py +6 -5
  108. reactivex/operators/_last.py +36 -31
  109. reactivex/operators/_lastordefault.py +8 -8
  110. reactivex/operators/_map.py +54 -39
  111. reactivex/operators/_materialize.py +30 -31
  112. reactivex/operators/_max.py +18 -11
  113. reactivex/operators/_maxby.py +5 -5
  114. reactivex/operators/_merge.py +132 -129
  115. reactivex/operators/_min.py +16 -10
  116. reactivex/operators/_minby.py +9 -8
  117. reactivex/operators/_multicast.py +9 -9
  118. reactivex/operators/_observeon.py +35 -31
  119. reactivex/operators/_onerrorresumenext.py +2 -1
  120. reactivex/operators/_pairwise.py +38 -34
  121. reactivex/operators/_partition.py +80 -73
  122. reactivex/operators/_pluck.py +4 -3
  123. reactivex/operators/_publish.py +36 -21
  124. reactivex/operators/_publishvalue.py +8 -7
  125. reactivex/operators/_reduce.py +16 -12
  126. reactivex/operators/_repeat.py +33 -30
  127. reactivex/operators/_replay.py +9 -9
  128. reactivex/operators/_retry.py +12 -10
  129. reactivex/operators/_sample.py +31 -27
  130. reactivex/operators/_scan.py +41 -39
  131. reactivex/operators/_sequenceequal.py +8 -7
  132. reactivex/operators/_single.py +20 -13
  133. reactivex/operators/_singleordefault.py +6 -5
  134. reactivex/operators/_skip.py +35 -32
  135. reactivex/operators/_skiplast.py +38 -34
  136. reactivex/operators/_skiplastwithtime.py +5 -4
  137. reactivex/operators/_skipuntil.py +40 -35
  138. reactivex/operators/_skipuntilwithtime.py +4 -3
  139. reactivex/operators/_skipwhile.py +65 -44
  140. reactivex/operators/_skipwithtime.py +50 -46
  141. reactivex/operators/_slice.py +58 -53
  142. reactivex/operators/_some.py +48 -47
  143. reactivex/operators/_startswith.py +17 -15
  144. reactivex/operators/_subscribeon.py +44 -41
  145. reactivex/operators/_sum.py +23 -6
  146. reactivex/operators/_switchlatest.py +71 -69
  147. reactivex/operators/_take.py +37 -33
  148. reactivex/operators/_takelast.py +37 -36
  149. reactivex/operators/_takelastbuffer.py +38 -37
  150. reactivex/operators/_takelastwithtime.py +60 -56
  151. reactivex/operators/_takeuntil.py +33 -32
  152. reactivex/operators/_takeuntilwithtime.py +42 -39
  153. reactivex/operators/_takewhile.py +108 -100
  154. reactivex/operators/_takewithtime.py +46 -41
  155. reactivex/operators/_throttlefirst.py +52 -45
  156. reactivex/operators/_timeinterval.py +40 -36
  157. reactivex/operators/_timeout.py +81 -79
  158. reactivex/operators/_timeoutwithmapper.py +6 -5
  159. reactivex/operators/_timestamp.py +24 -22
  160. reactivex/operators/_todict.py +51 -43
  161. reactivex/operators/_tofuture.py +24 -15
  162. reactivex/operators/_toiterable.py +33 -27
  163. reactivex/operators/_tomarbles.py +5 -5
  164. reactivex/operators/_toset.py +29 -19
  165. reactivex/operators/_whiledo.py +2 -1
  166. reactivex/operators/_window.py +100 -99
  167. reactivex/operators/_windowwithcount.py +56 -54
  168. reactivex/operators/_windowwithtime.py +95 -79
  169. reactivex/operators/_windowwithtimeorcount.py +85 -69
  170. reactivex/operators/_withlatestfrom.py +13 -9
  171. reactivex/operators/_zip.py +67 -63
  172. reactivex/operators/connectable/_refcount.py +4 -3
  173. reactivex/pipe.py +2 -1
  174. reactivex/run.py +8 -4
  175. reactivex/scheduler/catchscheduler.py +11 -10
  176. reactivex/scheduler/currentthreadscheduler.py +2 -3
  177. reactivex/scheduler/eventloop/asyncioscheduler.py +7 -6
  178. reactivex/scheduler/eventloop/asynciothreadsafescheduler.py +12 -14
  179. reactivex/scheduler/eventloop/eventletscheduler.py +4 -4
  180. reactivex/scheduler/eventloop/geventscheduler.py +4 -4
  181. reactivex/scheduler/eventloop/ioloopscheduler.py +4 -4
  182. reactivex/scheduler/eventloop/twistedscheduler.py +4 -4
  183. reactivex/scheduler/eventloopscheduler.py +9 -12
  184. reactivex/scheduler/historicalscheduler.py +1 -2
  185. reactivex/scheduler/immediatescheduler.py +5 -4
  186. reactivex/scheduler/mainloop/gtkscheduler.py +6 -7
  187. reactivex/scheduler/mainloop/pygamescheduler.py +4 -4
  188. reactivex/scheduler/mainloop/qtscheduler.py +6 -6
  189. reactivex/scheduler/mainloop/tkinterscheduler.py +4 -4
  190. reactivex/scheduler/mainloop/wxscheduler.py +7 -7
  191. reactivex/scheduler/newthreadscheduler.py +6 -8
  192. reactivex/scheduler/periodicscheduler.py +4 -4
  193. reactivex/scheduler/scheduleditem.py +4 -4
  194. reactivex/scheduler/scheduler.py +5 -5
  195. reactivex/scheduler/threadpoolscheduler.py +3 -3
  196. reactivex/scheduler/timeoutscheduler.py +5 -4
  197. reactivex/scheduler/trampoline.py +1 -2
  198. reactivex/scheduler/trampolinescheduler.py +5 -6
  199. reactivex/scheduler/virtualtimescheduler.py +4 -4
  200. reactivex/subject/asyncsubject.py +2 -2
  201. reactivex/subject/behaviorsubject.py +2 -2
  202. reactivex/subject/innersubscription.py +2 -2
  203. reactivex/subject/replaysubject.py +8 -8
  204. reactivex/subject/subject.py +4 -4
  205. reactivex/testing/coldobservable.py +5 -5
  206. reactivex/testing/hotobservable.py +6 -6
  207. reactivex/testing/marbles.py +21 -20
  208. reactivex/testing/mockdisposable.py +1 -3
  209. reactivex/testing/mockobserver.py +2 -2
  210. reactivex/testing/reactivetest.py +2 -2
  211. reactivex/testing/recorded.py +1 -1
  212. reactivex/testing/subscription.py +3 -3
  213. reactivex/testing/testscheduler.py +13 -12
  214. reactivex/typing.py +25 -14
  215. {reactivex-4.1.0.dist-info → reactivex-5.0.0a2.dist-info}/METADATA +59 -26
  216. reactivex-5.0.0a2.dist-info/RECORD +236 -0
  217. {reactivex-4.1.0.dist-info → reactivex-5.0.0a2.dist-info}/WHEEL +1 -1
  218. reactivex-4.1.0.dist-info/RECORD +0 -223
  219. {reactivex-4.1.0.dist-info → reactivex-5.0.0a2.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,59 @@
1
+ """Simplified curry_flip decorator for RxPY operators.
2
+
3
+ Adapted from Expression library (https://github.com/dbrattli/Expression)
4
+ Simplified to always curry_flip with 1 argument as that's the only case
5
+ needed for RxPY operators.
6
+ """
7
+
8
+ import functools
9
+ from collections.abc import Callable
10
+ from typing import Concatenate, TypeVar
11
+
12
+ from typing_extensions import ParamSpec
13
+
14
+ _P = ParamSpec("_P")
15
+ _A = TypeVar("_A")
16
+ _B = TypeVar("_B")
17
+
18
+
19
+ def curry_flip(
20
+ fun: Callable[Concatenate[_A, _P], _B],
21
+ ) -> Callable[_P, Callable[[_A], _B]]:
22
+ """A flipped curry decorator for single-argument currying.
23
+
24
+ Makes a function curried, but flips the curried argument to become
25
+ the last argument. This is perfect for RxPY operators where the source
26
+ Observable should be the last argument to enable piping.
27
+
28
+ This is a simplified version that always curries exactly 1 argument,
29
+ as that's all RxPY operators need.
30
+
31
+ Args:
32
+ fun: The function to curry-flip. Must take at least one argument.
33
+
34
+ Returns:
35
+ A curried function where the first argument becomes the last.
36
+
37
+ Example:
38
+ >>> @curry_flip
39
+ ... def take(count: int, source: Observable[int]) -> Observable[int]:
40
+ ... # implementation
41
+ ... pass
42
+ >>>
43
+ >>> # Now can be used in pipe:
44
+ >>> result = source.pipe(take(5))
45
+ >>> # Or called directly:
46
+ >>> result = take(5)(source)
47
+ """
48
+
49
+ @functools.wraps(fun)
50
+ def _wrap_args(*args: _P.args, **kwargs: _P.kwargs) -> Callable[[_A], _B]:
51
+ def _wrap_curried(curry_arg: _A) -> _B:
52
+ return fun(curry_arg, *args, **kwargs)
53
+
54
+ return _wrap_curried
55
+
56
+ return _wrap_args
57
+
58
+
59
+ __all__ = ["curry_flip"]
@@ -1,36 +1,31 @@
1
1
  # Rx Exceptions
2
2
 
3
3
 
4
- from typing import Optional
5
-
6
-
7
4
  class SequenceContainsNoElementsError(Exception):
8
- def __init__(self, msg: Optional[str] = None):
5
+ def __init__(self, msg: str | None = None):
9
6
  super().__init__(msg or "Sequence contains no elements")
10
7
 
11
8
 
12
9
  class ArgumentOutOfRangeException(ValueError):
13
- def __init__(self, msg: Optional[str] = None):
14
- super(ArgumentOutOfRangeException, self).__init__(
15
- msg or "Argument out of range"
16
- )
10
+ def __init__(self, msg: str | None = None):
11
+ super().__init__(msg or "Argument out of range")
17
12
 
18
13
 
19
14
  class DisposedException(Exception):
20
- def __init__(self, msg: Optional[str] = None):
15
+ def __init__(self, msg: str | None = None):
21
16
  super().__init__(msg or "Object has been disposed")
22
17
 
23
18
 
24
19
  class ReEntracyException(Exception):
25
- def __init__(self, msg: Optional[str] = None):
20
+ def __init__(self, msg: str | None = None):
26
21
  super().__init__(msg or "Re-entrancy detected")
27
22
 
28
23
 
29
24
  class CompletedException(Exception):
30
- def __init__(self, msg: Optional[str] = None):
25
+ def __init__(self, msg: str | None = None):
31
26
  super().__init__(msg or "Observer completed")
32
27
 
33
28
 
34
29
  class WouldBlockException(Exception):
35
- def __init__(self, msg: Optional[str] = None):
30
+ def __init__(self, msg: str | None = None):
36
31
  super().__init__(msg or "Would block")
@@ -1,6 +1,6 @@
1
1
  import heapq
2
2
  from sys import maxsize
3
- from typing import Generic, List, Tuple, TypeVar
3
+ from typing import Generic, TypeVar
4
4
 
5
5
  _T1 = TypeVar("_T1")
6
6
 
@@ -11,7 +11,7 @@ class PriorityQueue(Generic[_T1]):
11
11
  MIN_COUNT = ~maxsize
12
12
 
13
13
  def __init__(self) -> None:
14
- self.items: List[Tuple[_T1, int]] = []
14
+ self.items: list[tuple[_T1, int]] = []
15
15
  self.count = PriorityQueue.MIN_COUNT # Monotonic increasing for sort stability
16
16
 
17
17
  def __len__(self) -> int:
@@ -1,6 +1,7 @@
1
+ from collections.abc import Callable, Iterable
1
2
  from functools import update_wrapper
2
3
  from types import FunctionType
3
- from typing import TYPE_CHECKING, Any, Callable, Iterable, Optional, TypeVar, cast
4
+ from typing import TYPE_CHECKING, Any, TypeVar, cast
4
5
 
5
6
  from typing_extensions import ParamSpec
6
7
 
@@ -19,7 +20,7 @@ def add_ref(xs: "Observable[_T]", r: RefCountDisposable) -> "Observable[_T]":
19
20
  from reactivex import Observable
20
21
 
21
22
  def subscribe(
22
- observer: abc.ObserverBase[Any], scheduler: Optional[abc.SchedulerBase] = None
23
+ observer: abc.ObserverBase[Any], scheduler: abc.SchedulerBase | None = None
23
24
  ) -> abc.DisposableBase:
24
25
  return CompositeDisposable(r.disposable, xs.subscribe(observer))
25
26
 
reactivex/notification.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from abc import abstractmethod
2
- from typing import Any, Callable, Generic, Optional, TypeVar, Union
2
+ from collections.abc import Callable
3
+ from typing import Any, Generic, TypeVar, cast
3
4
 
4
5
  from reactivex import abc, typing
5
6
  from reactivex.scheduler import ImmediateScheduler
@@ -21,9 +22,9 @@ class Notification(Generic[_T]):
21
22
 
22
23
  def accept(
23
24
  self,
24
- on_next: Union[typing.OnNext[_T], abc.ObserverBase[_T]],
25
- on_error: Optional[typing.OnError] = None,
26
- on_completed: Optional[typing.OnCompleted] = None,
25
+ on_next: typing.OnNext[_T] | abc.ObserverBase[_T],
26
+ on_error: typing.OnError | None = None,
27
+ on_completed: typing.OnCompleted | None = None,
27
28
  ) -> None:
28
29
  """Invokes the delegate corresponding to the notification or an
29
30
  observer and returns the produced result.
@@ -43,7 +44,7 @@ class Notification(Generic[_T]):
43
44
  Result produced by the observation."""
44
45
 
45
46
  if isinstance(on_next, abc.ObserverBase):
46
- return self._accept_observer(on_next)
47
+ return self._accept_observer(cast(abc.ObserverBase[_T], on_next))
47
48
 
48
49
  return self._accept(on_next, on_error, on_completed)
49
50
 
@@ -51,8 +52,8 @@ class Notification(Generic[_T]):
51
52
  def _accept(
52
53
  self,
53
54
  on_next: typing.OnNext[_T],
54
- on_error: Optional[typing.OnError],
55
- on_completed: Optional[typing.OnCompleted],
55
+ on_error: typing.OnError | None,
56
+ on_completed: typing.OnCompleted | None,
56
57
  ) -> None:
57
58
  raise NotImplementedError
58
59
 
@@ -61,7 +62,7 @@ class Notification(Generic[_T]):
61
62
  raise NotImplementedError
62
63
 
63
64
  def to_observable(
64
- self, scheduler: Optional[abc.SchedulerBase] = None
65
+ self, scheduler: abc.SchedulerBase | None = None
65
66
  ) -> abc.ObservableBase[_T]:
66
67
  """Returns an observable sequence with a single notification,
67
68
  using the specified scheduler, else the immediate scheduler.
@@ -79,7 +80,7 @@ class Notification(Generic[_T]):
79
80
 
80
81
  def subscribe(
81
82
  observer: abc.ObserverBase[_T],
82
- scheduler: Optional[abc.SchedulerBase] = None,
83
+ scheduler: abc.SchedulerBase | None = None,
83
84
  ) -> abc.DisposableBase:
84
85
  def action(scheduler: abc.SchedulerBase, state: Any) -> None:
85
86
  self._accept_observer(observer)
@@ -108,7 +109,7 @@ class OnNext(Notification[_T]):
108
109
  def __init__(self, value: _T) -> None:
109
110
  """Constructs a notification of a new value."""
110
111
 
111
- super(OnNext, self).__init__()
112
+ super().__init__()
112
113
  self.value: _T = value
113
114
  self.has_value: bool = True
114
115
  self.kind: str = "N"
@@ -116,8 +117,8 @@ class OnNext(Notification[_T]):
116
117
  def _accept(
117
118
  self,
118
119
  on_next: typing.OnNext[_T],
119
- on_error: Optional[typing.OnError] = None,
120
- on_completed: Optional[typing.OnCompleted] = None,
120
+ on_error: typing.OnError | None = None,
121
+ on_completed: typing.OnCompleted | None = None,
121
122
  ) -> None:
122
123
  return on_next(self.value)
123
124
 
@@ -128,16 +129,16 @@ class OnNext(Notification[_T]):
128
129
  val: Any = self.value
129
130
  if isinstance(val, int):
130
131
  val = float(val)
131
- return "OnNext(%s)" % str(val)
132
+ return f"OnNext({str(val)})"
132
133
 
133
134
 
134
135
  class OnError(Notification[_T]):
135
136
  """Represents an OnError notification to an observer."""
136
137
 
137
- def __init__(self, error: Union[Exception, str]) -> None:
138
+ def __init__(self, error: Exception | str) -> None:
138
139
  """Constructs a notification of an exception."""
139
140
 
140
- super(OnError, self).__init__()
141
+ super().__init__()
141
142
  self.exception: Exception = (
142
143
  error if isinstance(error, Exception) else Exception(error)
143
144
  )
@@ -146,8 +147,8 @@ class OnError(Notification[_T]):
146
147
  def _accept(
147
148
  self,
148
149
  on_next: typing.OnNext[_T],
149
- on_error: Optional[typing.OnError],
150
- on_completed: Optional[typing.OnCompleted],
150
+ on_error: typing.OnError | None,
151
+ on_completed: typing.OnCompleted | None,
151
152
  ) -> None:
152
153
  return on_error(self.exception) if on_error else None
153
154
 
@@ -155,7 +156,7 @@ class OnError(Notification[_T]):
155
156
  return observer.on_error(self.exception)
156
157
 
157
158
  def __str__(self) -> str:
158
- return "OnError(%s)" % str(self.exception)
159
+ return f"OnError({str(self.exception)})"
159
160
 
160
161
 
161
162
  class OnCompleted(Notification[_T]):
@@ -164,14 +165,14 @@ class OnCompleted(Notification[_T]):
164
165
  def __init__(self) -> None:
165
166
  """Constructs a notification of the end of a sequence."""
166
167
 
167
- super(OnCompleted, self).__init__()
168
+ super().__init__()
168
169
  self.kind = "C"
169
170
 
170
171
  def _accept(
171
172
  self,
172
173
  on_next: typing.OnNext[_T],
173
- on_error: Optional[typing.OnError],
174
- on_completed: Optional[typing.OnCompleted],
174
+ on_error: typing.OnError | None,
175
+ on_completed: typing.OnCompleted | None,
175
176
  ) -> None:
176
177
  return on_completed() if on_completed else None
177
178
 
@@ -1,5 +1,6 @@
1
1
  from asyncio import Future
2
- from typing import Callable, Mapping, Optional, TypeVar, Union
2
+ from collections.abc import Callable, Mapping
3
+ from typing import TypeVar, Union
3
4
 
4
5
  from reactivex import Observable, abc, defer, empty, from_future
5
6
 
@@ -10,19 +11,17 @@ _T = TypeVar("_T")
10
11
  def case_(
11
12
  mapper: Callable[[], _Key],
12
13
  sources: Mapping[_Key, Observable[_T]],
13
- default_source: Optional[Union[Observable[_T], "Future[_T]"]] = None,
14
+ default_source: Union[Observable[_T], "Future[_T]"] | None = None,
14
15
  ) -> Observable[_T]:
15
-
16
- default_source_: Union[Observable[_T], "Future[_T]"] = default_source or empty()
16
+ default_source_: Observable[_T] | Future[_T] = default_source or empty()
17
17
 
18
18
  def factory(_: abc.SchedulerBase) -> Observable[_T]:
19
19
  try:
20
- result: Union[Observable[_T], "Future[_T]"] = sources[mapper()]
20
+ result: Observable[_T] | Future[_T] = sources[mapper()]
21
21
  except KeyError:
22
22
  result = default_source_
23
23
 
24
24
  if isinstance(result, Future):
25
-
26
25
  result_: Observable[_T] = from_future(result)
27
26
  else:
28
27
  result_ = result
@@ -1,4 +1,5 @@
1
- from typing import Any, Iterable, Optional, TypeVar
1
+ from collections.abc import Iterable
2
+ from typing import Any, TypeVar
2
3
 
3
4
  from reactivex import Observable, abc
4
5
  from reactivex.disposable import (
@@ -32,7 +33,7 @@ def catch_with_iterable_(sources: Iterable[Observable[_T]]) -> Observable[_T]:
32
33
  sources_ = iter(sources)
33
34
 
34
35
  def subscribe(
35
- observer: abc.ObserverBase[_T], scheduler_: Optional[abc.SchedulerBase] = None
36
+ observer: abc.ObserverBase[_T], scheduler_: abc.SchedulerBase | None = None
36
37
  ) -> abc.DisposableBase:
37
38
  _scheduler = scheduler_ or CurrentThreadScheduler.singleton()
38
39
 
@@ -1,10 +1,10 @@
1
- from typing import Any, List, Optional, Tuple
1
+ from typing import Any
2
2
 
3
3
  from reactivex import Observable, abc
4
4
  from reactivex.disposable import CompositeDisposable, SingleAssignmentDisposable
5
5
 
6
6
 
7
- def combine_latest_(*sources: Observable[Any]) -> Observable[Tuple[Any, ...]]:
7
+ def combine_latest_(*sources: Observable[Any]) -> Observable[tuple[Any, ...]]:
8
8
  """Merges the specified observable sequences into one observable
9
9
  sequence by creating a tuple whenever any of the
10
10
  observable sequences produces an element.
@@ -20,9 +20,8 @@ def combine_latest_(*sources: Observable[Any]) -> Observable[Tuple[Any, ...]]:
20
20
  parent = sources[0]
21
21
 
22
22
  def subscribe(
23
- observer: abc.ObserverBase[Any], scheduler: Optional[abc.SchedulerBase] = None
23
+ observer: abc.ObserverBase[Any], scheduler: abc.SchedulerBase | None = None
24
24
  ) -> CompositeDisposable:
25
-
26
25
  n = len(sources)
27
26
  has_value = [False] * n
28
27
  has_value_all = [False]
@@ -46,7 +45,7 @@ def combine_latest_(*sources: Observable[Any]) -> Observable[Tuple[Any, ...]]:
46
45
  if all(is_done):
47
46
  observer.on_completed()
48
47
 
49
- subscriptions: List[Optional[SingleAssignmentDisposable]] = [None] * n
48
+ subscriptions: list[SingleAssignmentDisposable | None] = [None] * n
50
49
 
51
50
  def func(i: int) -> None:
52
51
  subscriptions[i] = SingleAssignmentDisposable()
@@ -1,4 +1,5 @@
1
- from typing import Any, Iterable, Optional, TypeVar
1
+ from collections.abc import Iterable
2
+ from typing import Any, TypeVar
2
3
 
3
4
  from reactivex import Observable, abc
4
5
  from reactivex.disposable import (
@@ -14,7 +15,7 @@ _T = TypeVar("_T")
14
15
 
15
16
  def concat_with_iterable_(sources: Iterable[Observable[_T]]) -> Observable[_T]:
16
17
  def subscribe(
17
- observer: abc.ObserverBase[_T], scheduler_: Optional[abc.SchedulerBase] = None
18
+ observer: abc.ObserverBase[_T], scheduler_: abc.SchedulerBase | None = None
18
19
  ) -> abc.DisposableBase:
19
20
  _scheduler = scheduler_ or CurrentThreadScheduler.singleton()
20
21
 
@@ -1,4 +1,4 @@
1
- from typing import List, Optional, TypeVar
1
+ from typing import TypeVar
2
2
 
3
3
  from reactivex import abc
4
4
  from reactivex.disposable import CompositeDisposable, Disposable
@@ -15,7 +15,7 @@ class ConnectableObservable(Observable[_T]):
15
15
  def __init__(self, source: abc.ObservableBase[_T], subject: abc.SubjectBase[_T]):
16
16
  self.subject = subject
17
17
  self.has_subscription = False
18
- self.subscription: Optional[abc.DisposableBase] = None
18
+ self.subscription: abc.DisposableBase | None = None
19
19
  self.source = source
20
20
 
21
21
  super().__init__()
@@ -23,13 +23,13 @@ class ConnectableObservable(Observable[_T]):
23
23
  def _subscribe_core(
24
24
  self,
25
25
  observer: abc.ObserverBase[_T],
26
- scheduler: Optional[abc.SchedulerBase] = None,
26
+ scheduler: abc.SchedulerBase | None = None,
27
27
  ) -> abc.DisposableBase:
28
28
  return self.subject.subscribe(observer, scheduler=scheduler)
29
29
 
30
30
  def connect(
31
- self, scheduler: Optional[abc.SchedulerBase] = None
32
- ) -> Optional[abc.DisposableBase]:
31
+ self, scheduler: abc.SchedulerBase | None = None
32
+ ) -> abc.DisposableBase | None:
33
33
  """Connects the observable."""
34
34
 
35
35
  if not self.has_subscription:
@@ -52,7 +52,7 @@ class ConnectableObservable(Observable[_T]):
52
52
  subscribers.
53
53
  """
54
54
 
55
- connectable_subscription: List[Optional[abc.DisposableBase]] = [None]
55
+ connectable_subscription: list[abc.DisposableBase | None] = [None]
56
56
  count = [0]
57
57
  source = self
58
58
  is_connected = [False]
@@ -63,7 +63,7 @@ class ConnectableObservable(Observable[_T]):
63
63
 
64
64
  def subscribe(
65
65
  observer: abc.ObserverBase[_T],
66
- scheduler: Optional[abc.SchedulerBase] = None,
66
+ scheduler: abc.SchedulerBase | None = None,
67
67
  ) -> abc.DisposableBase:
68
68
  count[0] += 1
69
69
  should_connect = count[0] == subscriber_count and not is_connected[0]
@@ -1,5 +1,6 @@
1
1
  from asyncio import Future
2
- from typing import Callable, Optional, TypeVar, Union
2
+ from collections.abc import Callable
3
+ from typing import TypeVar, Union
3
4
 
4
5
  from reactivex import Observable, abc, from_future, throw
5
6
  from reactivex.scheduler import ImmediateScheduler
@@ -8,7 +9,7 @@ _T = TypeVar("_T")
8
9
 
9
10
 
10
11
  def defer_(
11
- factory: Callable[[abc.SchedulerBase], Union[Observable[_T], "Future[_T]"]]
12
+ factory: Callable[[abc.SchedulerBase], Union[Observable[_T], "Future[_T]"]],
12
13
  ) -> Observable[_T]:
13
14
  """Returns an observable sequence that invokes the specified factory
14
15
  function whenever a new observer subscribes.
@@ -27,7 +28,7 @@ def defer_(
27
28
  """
28
29
 
29
30
  def subscribe(
30
- observer: abc.ObserverBase[_T], scheduler: Optional[abc.SchedulerBase] = None
31
+ observer: abc.ObserverBase[_T], scheduler: abc.SchedulerBase | None = None
31
32
  ) -> abc.DisposableBase:
32
33
  try:
33
34
  result = factory(scheduler or ImmediateScheduler.singleton())
@@ -1,14 +1,13 @@
1
- from typing import Any, Optional
1
+ from typing import Any
2
2
 
3
3
  from reactivex import Observable, abc
4
4
  from reactivex.scheduler import ImmediateScheduler
5
5
 
6
6
 
7
- def empty_(scheduler: Optional[abc.SchedulerBase] = None) -> Observable[Any]:
7
+ def empty_(scheduler: abc.SchedulerBase | None = None) -> Observable[Any]:
8
8
  def subscribe(
9
- observer: abc.ObserverBase[Any], scheduler_: Optional[abc.SchedulerBase] = None
9
+ observer: abc.ObserverBase[Any], scheduler_: abc.SchedulerBase | None = None
10
10
  ) -> abc.DisposableBase:
11
-
12
11
  _scheduler = scheduler or scheduler_ or ImmediateScheduler.singleton()
13
12
 
14
13
  def action(_: abc.SchedulerBase, __: Any) -> None:
@@ -1,10 +1,10 @@
1
- from typing import Any, List, Optional, Tuple, cast
1
+ from typing import Any, cast
2
2
 
3
3
  from reactivex import Observable, abc
4
4
  from reactivex.disposable import CompositeDisposable, SingleAssignmentDisposable
5
5
 
6
6
 
7
- def fork_join_(*sources: Observable[Any]) -> Observable[Tuple[Any, ...]]:
7
+ def fork_join_(*sources: Observable[Any]) -> Observable[tuple[Any, ...]]:
8
8
  """Wait for observables to complete and then combine last values
9
9
  they emitted into a tuple. Whenever any of that observables completes
10
10
  without emitting any value, result sequence will complete at that moment as well.
@@ -20,8 +20,8 @@ def fork_join_(*sources: Observable[Any]) -> Observable[Tuple[Any, ...]]:
20
20
  parent = sources[0]
21
21
 
22
22
  def subscribe(
23
- observer: abc.ObserverBase[Tuple[Any, ...]],
24
- scheduler: Optional[abc.SchedulerBase] = None,
23
+ observer: abc.ObserverBase[tuple[Any, ...]],
24
+ scheduler: abc.SchedulerBase | None = None,
25
25
  ) -> abc.DisposableBase:
26
26
  n = len(sources)
27
27
  values = [None] * n
@@ -42,7 +42,7 @@ def fork_join_(*sources: Observable[Any]) -> Observable[Tuple[Any, ...]]:
42
42
  else:
43
43
  observer.on_completed()
44
44
 
45
- subscriptions: List[SingleAssignmentDisposable] = [
45
+ subscriptions: list[SingleAssignmentDisposable] = [
46
46
  cast(SingleAssignmentDisposable, None)
47
47
  ] * n
48
48
 
@@ -1,4 +1,5 @@
1
- from typing import Any, Callable, Optional
1
+ from collections.abc import Callable
2
+ from typing import Any
2
3
 
3
4
  from reactivex import Observable, abc, typing
4
5
  from reactivex.disposable import Disposable
@@ -6,7 +7,7 @@ from reactivex.disposable import Disposable
6
7
 
7
8
  def from_callback_(
8
9
  func: Callable[..., Callable[..., None]],
9
- mapper: Optional[typing.Mapper[Any, Any]] = None,
10
+ mapper: typing.Mapper[Any, Any] | None = None,
10
11
  ) -> Callable[[], Observable[Any]]:
11
12
  """Converts a callback function to an observable sequence.
12
13
 
@@ -27,7 +28,7 @@ def from_callback_(
27
28
 
28
29
  def subscribe(
29
30
  observer: abc.ObserverBase[Any],
30
- scheduler: Optional[abc.SchedulerBase] = None,
31
+ scheduler: abc.SchedulerBase | None = None,
31
32
  ) -> abc.DisposableBase:
32
33
  def handler(*args: Any) -> None:
33
34
  results = list(args)
@@ -1,6 +1,6 @@
1
1
  import asyncio
2
2
  from asyncio import Future
3
- from typing import Any, Optional, TypeVar, cast
3
+ from typing import Any, TypeVar, cast
4
4
 
5
5
  from reactivex import Observable, abc
6
6
  from reactivex.disposable import Disposable
@@ -21,7 +21,7 @@ def from_future_(future: "Future[_T]") -> Observable[_T]:
21
21
  """
22
22
 
23
23
  def subscribe(
24
- observer: abc.ObserverBase[Any], scheduler: Optional[abc.SchedulerBase] = None
24
+ observer: abc.ObserverBase[Any], scheduler: abc.SchedulerBase | None = None
25
25
  ) -> abc.DisposableBase:
26
26
  def done(future: "Future[_T]") -> None:
27
27
  try:
@@ -1,4 +1,5 @@
1
- from typing import Any, Iterable, Optional, TypeVar
1
+ from collections.abc import Iterable
2
+ from typing import Any, TypeVar
2
3
 
3
4
  from reactivex import Observable, abc
4
5
  from reactivex.disposable import CompositeDisposable, Disposable
@@ -8,7 +9,7 @@ _T = TypeVar("_T")
8
9
 
9
10
 
10
11
  def from_iterable_(
11
- iterable: Iterable[_T], scheduler: Optional[abc.SchedulerBase] = None
12
+ iterable: Iterable[_T], scheduler: abc.SchedulerBase | None = None
12
13
  ) -> Observable[_T]:
13
14
  """Converts an iterable to an observable sequence.
14
15
 
@@ -25,7 +26,7 @@ def from_iterable_(
25
26
  """
26
27
 
27
28
  def subscribe(
28
- observer: abc.ObserverBase[_T], scheduler_: Optional[abc.SchedulerBase] = None
29
+ observer: abc.ObserverBase[_T], scheduler_: abc.SchedulerBase | None = None
29
30
  ) -> abc.DisposableBase:
30
31
  _scheduler = scheduler or scheduler_ or CurrentThreadScheduler.singleton()
31
32
  iterator = iter(iterable)
@@ -1,4 +1,4 @@
1
- from typing import Any, Optional, TypeVar, cast
1
+ from typing import Any, TypeVar, cast
2
2
 
3
3
  from reactivex import Observable, abc, typing
4
4
  from reactivex.disposable import MultipleAssignmentDisposable
@@ -14,7 +14,7 @@ def generate_(
14
14
  ) -> Observable[_TState]:
15
15
  def subscribe(
16
16
  observer: abc.ObserverBase[_TState],
17
- scheduler: Optional[abc.SchedulerBase] = None,
17
+ scheduler: abc.SchedulerBase | None = None,
18
18
  ) -> abc.DisposableBase:
19
19
  scheduler = scheduler or CurrentThreadScheduler.singleton()
20
20
  first = True
@@ -1,4 +1,5 @@
1
- from typing import Any, Callable, Optional, TypeVar, cast
1
+ from collections.abc import Callable
2
+ from typing import Any, TypeVar, cast
2
3
 
3
4
  from reactivex import Observable, abc
4
5
  from reactivex.disposable import MultipleAssignmentDisposable
@@ -38,7 +39,7 @@ def generate_with_relative_time_(
38
39
 
39
40
  def subscribe(
40
41
  observer: abc.ObserverBase[_TState],
41
- scheduler: Optional[abc.SchedulerBase] = None,
42
+ scheduler: abc.SchedulerBase | None = None,
42
43
  ) -> abc.DisposableBase:
43
44
  scheduler = scheduler or TimeoutScheduler.singleton()
44
45
  mad = MultipleAssignmentDisposable()
@@ -46,7 +47,7 @@ def generate_with_relative_time_(
46
47
  has_result = False
47
48
  result: _TState = cast(_TState, None)
48
49
  first = True
49
- time: Optional[RelativeTime] = None
50
+ time: RelativeTime | None = None
50
51
 
51
52
  def action(scheduler: abc.SchedulerBase, _: Any) -> None:
52
53
  nonlocal state
@@ -1,4 +1,4 @@
1
- from typing import Generic, Optional, TypeVar
1
+ from typing import Generic, TypeVar
2
2
 
3
3
  from reactivex import abc
4
4
  from reactivex.disposable import CompositeDisposable, Disposable, RefCountDisposable
@@ -14,14 +14,14 @@ class GroupedObservable(Generic[_TKey, _T], Observable[_T]):
14
14
  self,
15
15
  key: _TKey,
16
16
  underlying_observable: Observable[_T],
17
- merged_disposable: Optional[RefCountDisposable] = None,
17
+ merged_disposable: RefCountDisposable | None = None,
18
18
  ):
19
19
  super().__init__()
20
20
  self.key = key
21
21
 
22
22
  def subscribe(
23
23
  observer: abc.ObserverBase[_T],
24
- scheduler: Optional[abc.SchedulerBase] = None,
24
+ scheduler: abc.SchedulerBase | None = None,
25
25
  ) -> abc.DisposableBase:
26
26
  return CompositeDisposable(
27
27
  merged_disposable.disposable if merged_disposable else Disposable(),
@@ -35,6 +35,6 @@ class GroupedObservable(Generic[_TKey, _T], Observable[_T]):
35
35
  def _subscribe_core(
36
36
  self,
37
37
  observer: abc.ObserverBase[_T],
38
- scheduler: Optional[abc.SchedulerBase] = None,
38
+ scheduler: abc.SchedulerBase | None = None,
39
39
  ) -> abc.DisposableBase:
40
40
  return self.underlying_observable.subscribe(observer, scheduler=scheduler)
@@ -1,5 +1,6 @@
1
1
  from asyncio import Future
2
- from typing import Callable, TypeVar, Union
2
+ from collections.abc import Callable
3
+ from typing import TypeVar, Union
3
4
 
4
5
  import reactivex
5
6
  from reactivex import Observable, abc
@@ -33,7 +34,7 @@ def if_then_(
33
34
  else_source.
34
35
  """
35
36
 
36
- else_source_: Union[Observable[_T], "Future[_T]"] = else_source or reactivex.empty()
37
+ else_source_: Observable[_T] | Future[_T] = else_source or reactivex.empty()
37
38
 
38
39
  then_source = (
39
40
  reactivex.from_future(then_source)