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
@@ -3,7 +3,8 @@ from __future__ import annotations
3
3
 
4
4
  import asyncio
5
5
  import threading
6
- from typing import Any, Callable, Generator, Optional, TypeVar, Union, cast, overload
6
+ from collections.abc import Callable, Generator
7
+ from typing import Any, TypeVar, cast, overload
7
8
 
8
9
  from reactivex import abc
9
10
  from reactivex.disposable import Disposable
@@ -11,6 +12,19 @@ from reactivex.scheduler import CurrentThreadScheduler
11
12
  from reactivex.scheduler.eventloop import AsyncIOScheduler
12
13
 
13
14
  from ..observer import AutoDetachObserver
15
+ from .mixins import (
16
+ CombinationMixin,
17
+ ConditionalMixin,
18
+ ErrorHandlingMixin,
19
+ FilteringMixin,
20
+ MathematicalMixin,
21
+ MulticastingMixin,
22
+ TestingMixin,
23
+ TimeBasedMixin,
24
+ TransformationMixin,
25
+ UtilityMixin,
26
+ WindowingMixin,
27
+ )
14
28
 
15
29
  _A = TypeVar("_A")
16
30
  _B = TypeVar("_B")
@@ -23,13 +37,41 @@ _G = TypeVar("_G")
23
37
  _T_out = TypeVar("_T_out", covariant=True)
24
38
 
25
39
 
26
- class Observable(abc.ObservableBase[_T_out]):
27
- """Observable base class.
28
-
29
- Represents a push-style collection, which you can :func:`pipe <pipe>` into
30
- :mod:`operators <reactivex.operators>`."""
31
-
32
- def __init__(self, subscribe: Optional[abc.Subscription[_T_out]] = None) -> None:
40
+ class Observable(
41
+ abc.ObservableBase[_T_out],
42
+ TransformationMixin[_T_out],
43
+ FilteringMixin[_T_out],
44
+ CombinationMixin[_T_out],
45
+ MathematicalMixin[_T_out],
46
+ ConditionalMixin[_T_out],
47
+ ErrorHandlingMixin[_T_out],
48
+ UtilityMixin[_T_out],
49
+ TimeBasedMixin[_T_out],
50
+ WindowingMixin[_T_out],
51
+ MulticastingMixin[_T_out],
52
+ TestingMixin[_T_out],
53
+ ):
54
+ """Observable with method chaining support.
55
+
56
+ Represents a push-style collection that supports both functional (pipe-based)
57
+ and fluent (method chaining) styles. You can :func:`pipe <pipe>` into
58
+ :mod:`operators <reactivex.operators>` or call operator methods directly.
59
+
60
+ The Observable class combines all operator categories through mixins:
61
+ - TransformationMixin: map, reduce, scan, flat_map, etc.
62
+ - FilteringMixin: filter, take, skip, distinct, etc.
63
+ - CombinationMixin: merge, zip, combine_latest, etc.
64
+ - MathematicalMixin: count, sum, average, min, max
65
+ - ConditionalMixin: default_if_empty, etc.
66
+ - ErrorHandlingMixin: catch, retry, on_error_resume_next
67
+ - UtilityMixin: do_action, delay, timestamp, etc.
68
+ - TimeBasedMixin: sample, debounce, etc.
69
+ - WindowingMixin: buffer, group_by, partition, etc.
70
+ - MulticastingMixin: share, publish, replay, etc.
71
+ - TestingMixin: all, some, is_empty, contains, etc.
72
+ """
73
+
74
+ def __init__(self, subscribe: abc.Subscription[_T_out] | None = None) -> None:
33
75
  """Creates an observable sequence object from the specified
34
76
  subscription function.
35
77
 
@@ -44,19 +86,17 @@ class Observable(abc.ObservableBase[_T_out]):
44
86
  def _subscribe_core(
45
87
  self,
46
88
  observer: abc.ObserverBase[_T_out],
47
- scheduler: Optional[abc.SchedulerBase] = None,
89
+ scheduler: abc.SchedulerBase | None = None,
48
90
  ) -> abc.DisposableBase:
49
91
  return self._subscribe(observer, scheduler) if self._subscribe else Disposable()
50
92
 
51
93
  def subscribe(
52
94
  self,
53
- on_next: Optional[
54
- Union[abc.ObserverBase[_T_out], abc.OnNext[_T_out], None]
55
- ] = None,
56
- on_error: Optional[abc.OnError] = None,
57
- on_completed: Optional[abc.OnCompleted] = None,
95
+ on_next: abc.ObserverBase[_T_out] | abc.OnNext[_T_out] | None | None = None,
96
+ on_error: abc.OnError | None = None,
97
+ on_completed: abc.OnCompleted | None = None,
58
98
  *,
59
- scheduler: Optional[abc.SchedulerBase] = None,
99
+ scheduler: abc.SchedulerBase | None = None,
60
100
  ) -> abc.DisposableBase:
61
101
  """Subscribe an observer to the observable sequence.
62
102
 
@@ -88,7 +128,7 @@ class Observable(abc.ObservableBase[_T_out]):
88
128
 
89
129
  Returns:
90
130
  Disposable object representing an observer's subscription to
91
- the observable sequence.
131
+ the observable sequence. Call :code:`.dispose()` on it to unsubscribe.
92
132
  """
93
133
  if (
94
134
  isinstance(on_next, abc.ObserverBase)
@@ -105,7 +145,7 @@ class Observable(abc.ObservableBase[_T_out]):
105
145
  )
106
146
 
107
147
  def fix_subscriber(
108
- subscriber: Union[abc.DisposableBase, Callable[[], None]]
148
+ subscriber: abc.DisposableBase | Callable[[], None],
109
149
  ) -> abc.DisposableBase:
110
150
  """Fixes subscriber to make sure it returns a Disposable instead
111
151
  of None or a dispose function"""
@@ -118,9 +158,7 @@ class Observable(abc.ObservableBase[_T_out]):
118
158
 
119
159
  return Disposable(subscriber)
120
160
 
121
- def set_disposable(
122
- _: Optional[abc.SchedulerBase] = None, __: Any = None
123
- ) -> None:
161
+ def set_disposable(_: abc.SchedulerBase | None = None, __: Any = None) -> None:
124
162
  try:
125
163
  subscriber = self._subscribe_core(auto_detach_observer, scheduler)
126
164
  except Exception as ex: # By design. pylint: disable=W0703
@@ -229,7 +267,7 @@ class Observable(abc.ObservableBase[_T_out]):
229
267
 
230
268
  return pipe_(self, *operators)
231
269
 
232
- def run(self) -> Any:
270
+ def run(self, scheduler: abc.SchedulerBase | None = None) -> _T_out:
233
271
  """Run source synchronously.
234
272
 
235
273
  Subscribes to the observable source. Then blocks and waits for the
@@ -249,7 +287,7 @@ class Observable(abc.ObservableBase[_T_out]):
249
287
  """
250
288
  from ..run import run
251
289
 
252
- return run(self)
290
+ return run(self, scheduler)
253
291
 
254
292
  def __await__(self) -> Generator[Any, None, _T_out]:
255
293
  """Awaits the given observable.
@@ -259,7 +297,11 @@ class Observable(abc.ObservableBase[_T_out]):
259
297
  """
260
298
  from ..operators._tofuture import to_future_
261
299
 
262
- loop = asyncio.get_event_loop()
300
+ try:
301
+ loop = asyncio.get_running_loop()
302
+ except RuntimeError:
303
+ loop = asyncio.new_event_loop()
304
+
263
305
  future: asyncio.Future[_T_out] = self.pipe(
264
306
  to_future_(scheduler=AsyncIOScheduler(loop=loop))
265
307
  )
@@ -281,7 +323,7 @@ class Observable(abc.ObservableBase[_T_out]):
281
323
 
282
324
  return concat(self, other)
283
325
 
284
- def __iadd__(self, other: Observable[_T_out]) -> "Observable[_T_out]":
326
+ def __iadd__(self, other: Observable[_T_out]) -> Observable[_T_out]:
285
327
  """Pythonic use of :func:`concat <reactivex.concat>`.
286
328
 
287
329
  Example:
@@ -297,7 +339,7 @@ class Observable(abc.ObservableBase[_T_out]):
297
339
 
298
340
  return concat(self, other)
299
341
 
300
- def __getitem__(self, key: Union[slice, int]) -> Observable[_T_out]:
342
+ def __getitem__(self, key: slice | int) -> Observable[_T_out]:
301
343
  """
302
344
  Pythonic version of :func:`slice <reactivex.operators.slice>`.
303
345
 
@@ -346,5 +388,10 @@ class Observable(abc.ObservableBase[_T_out]):
346
388
 
347
389
  return slice_(start, stop, step)(self)
348
390
 
391
+ # All operator methods are provided by mixins:
392
+ # TransformationMixin, FilteringMixin, CombinationMixin, MathematicalMixin,
393
+ # ConditionalMixin, ErrorHandlingMixin, UtilityMixin, TimeBasedMixin,
394
+ # WindowingMixin, MulticastingMixin, TestingMixin
395
+
349
396
 
350
397
  __all__ = ["Observable"]
@@ -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
  import reactivex
5
6
  from reactivex import Observable, abc
@@ -15,8 +16,8 @@ _T = TypeVar("_T")
15
16
 
16
17
  def on_error_resume_next_(
17
18
  *sources: Union[
18
- Observable[_T], "Future[_T]", Callable[[Optional[Exception]], Observable[_T]]
19
- ]
19
+ Observable[_T], "Future[_T]", Callable[[Exception | None], Observable[_T]]
20
+ ],
20
21
  ) -> Observable[_T]:
21
22
  """Continues an observable sequence that is terminated normally or
22
23
  by an exception with the next observable sequence.
@@ -32,7 +33,7 @@ def on_error_resume_next_(
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
 
@@ -40,7 +41,7 @@ def on_error_resume_next_(
40
41
  cancelable = SerialDisposable()
41
42
 
42
43
  def action(
43
- scheduler: abc.SchedulerBase, state: Optional[Exception] = None
44
+ scheduler: abc.SchedulerBase, state: Exception | None = None
44
45
  ) -> None:
45
46
  try:
46
47
  source = next(sources_)
@@ -57,7 +58,7 @@ def on_error_resume_next_(
57
58
  d = SingleAssignmentDisposable()
58
59
  subscription.disposable = d
59
60
 
60
- def on_resume(state: Optional[Exception] = None) -> None:
61
+ def on_resume(state: Exception | None = None) -> None:
61
62
  scheduler.schedule(action, state)
62
63
 
63
64
  d.disposable = current.subscribe(
@@ -1,5 +1,5 @@
1
+ from collections.abc import Iterator
1
2
  from sys import maxsize
2
- from typing import Iterator, Optional
3
3
 
4
4
  from reactivex import Observable, abc
5
5
  from reactivex.disposable import MultipleAssignmentDisposable
@@ -8,9 +8,9 @@ from reactivex.scheduler import CurrentThreadScheduler
8
8
 
9
9
  def range_(
10
10
  start: int,
11
- stop: Optional[int] = None,
12
- step: Optional[int] = None,
13
- scheduler: Optional[abc.SchedulerBase] = None,
11
+ stop: int | None = None,
12
+ step: int | None = None,
13
+ scheduler: abc.SchedulerBase | None = None,
14
14
  ) -> Observable[int]:
15
15
  """Generates an observable sequence of integral numbers within a
16
16
  specified range, using the specified scheduler to send out observer
@@ -44,7 +44,7 @@ def range_(
44
44
  range_t = range(start, _stop, _step)
45
45
 
46
46
  def subscribe(
47
- observer: abc.ObserverBase[int], scheduler_: Optional[abc.SchedulerBase] = None
47
+ observer: abc.ObserverBase[int], scheduler_: abc.SchedulerBase | None = None
48
48
  ) -> abc.DisposableBase:
49
49
  nonlocal range_t
50
50
 
@@ -52,7 +52,7 @@ def range_(
52
52
  sd = MultipleAssignmentDisposable()
53
53
 
54
54
  def action(
55
- scheduler: abc.SchedulerBase, iterator: Optional[Iterator[int]]
55
+ scheduler: abc.SchedulerBase, iterator: Iterator[int] | None
56
56
  ) -> None:
57
57
  try:
58
58
  assert iterator
@@ -1,4 +1,4 @@
1
- from typing import Optional, TypeVar
1
+ from typing import TypeVar
2
2
 
3
3
  import reactivex
4
4
  from reactivex import Observable
@@ -7,7 +7,7 @@ from reactivex import operators as ops
7
7
  _T = TypeVar("_T")
8
8
 
9
9
 
10
- def repeat_value_(value: _T, repeat_count: Optional[int] = None) -> Observable[_T]:
10
+ def repeat_value_(value: _T, repeat_count: int | None = None) -> Observable[_T]:
11
11
  """Generates an observable sequence that repeats the given element
12
12
  the specified number of times.
13
13
 
@@ -1,4 +1,5 @@
1
- from typing import Any, Callable, Optional, TypeVar
1
+ from collections.abc import Callable
2
+ from typing import Any, TypeVar
2
3
 
3
4
  from reactivex import Observable, abc
4
5
  from reactivex.scheduler import CurrentThreadScheduler
@@ -7,7 +8,7 @@ _T = TypeVar("_T")
7
8
 
8
9
 
9
10
  def return_value_(
10
- value: _T, scheduler: Optional[abc.SchedulerBase] = None
11
+ value: _T, scheduler: abc.SchedulerBase | None = None
11
12
  ) -> Observable[_T]:
12
13
  """Returns an observable sequence that contains a single element,
13
14
  using the specified scheduler to send out observer messages.
@@ -26,7 +27,7 @@ def return_value_(
26
27
  """
27
28
 
28
29
  def subscribe(
29
- observer: abc.ObserverBase[_T], scheduler_: Optional[abc.SchedulerBase] = None
30
+ observer: abc.ObserverBase[_T], scheduler_: abc.SchedulerBase | None = None
30
31
  ) -> abc.DisposableBase:
31
32
  _scheduler = scheduler or scheduler_ or CurrentThreadScheduler.singleton()
32
33
 
@@ -40,10 +41,10 @@ def return_value_(
40
41
 
41
42
 
42
43
  def from_callable_(
43
- supplier: Callable[[], _T], scheduler: Optional[abc.SchedulerBase] = None
44
+ supplier: Callable[[], _T], scheduler: abc.SchedulerBase | None = None
44
45
  ) -> Observable[_T]:
45
46
  def subscribe(
46
- observer: abc.ObserverBase[_T], scheduler_: Optional[abc.SchedulerBase] = None
47
+ observer: abc.ObserverBase[_T], scheduler_: abc.SchedulerBase | None = None
47
48
  ) -> abc.DisposableBase:
48
49
  _scheduler = scheduler or scheduler_ or CurrentThreadScheduler.singleton()
49
50
 
@@ -1,4 +1,5 @@
1
- from typing import Callable, Optional, TypeVar
1
+ from collections.abc import Callable
2
+ from typing import TypeVar
2
3
 
3
4
  from reactivex import Observable, abc, to_async
4
5
 
@@ -6,7 +7,7 @@ _T = TypeVar("_T")
6
7
 
7
8
 
8
9
  def start_(
9
- func: Callable[[], _T], scheduler: Optional[abc.SchedulerBase] = None
10
+ func: Callable[[], _T], scheduler: abc.SchedulerBase | None = None
10
11
  ) -> Observable[_T]:
11
12
  """Invokes the specified function asynchronously on the specified
12
13
  scheduler, surfacing the result through an observable sequence.
@@ -1,5 +1,6 @@
1
1
  from asyncio import Future
2
- from typing import Callable, TypeVar
2
+ from collections.abc import Callable
3
+ from typing import TypeVar
3
4
 
4
5
  from reactivex import Observable, from_future, throw
5
6
 
@@ -1,16 +1,16 @@
1
- from typing import Any, Optional, Union
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
7
  def throw_(
8
- exception: Union[str, Exception], scheduler: Optional[abc.SchedulerBase] = None
8
+ exception: str | Exception, scheduler: abc.SchedulerBase | None = None
9
9
  ) -> Observable[Any]:
10
10
  exception_ = exception if isinstance(exception, Exception) else Exception(exception)
11
11
 
12
12
  def subscribe(
13
- observer: abc.ObserverBase[Any], scheduler: Optional[abc.SchedulerBase] = None
13
+ observer: abc.ObserverBase[Any], scheduler: abc.SchedulerBase | None = None
14
14
  ) -> abc.DisposableBase:
15
15
  _scheduler = scheduler or ImmediateScheduler.singleton()
16
16
 
@@ -1,5 +1,5 @@
1
1
  from datetime import datetime
2
- from typing import Any, Optional
2
+ from typing import Any
3
3
 
4
4
  from reactivex import Observable, abc, typing
5
5
  from reactivex.disposable import MultipleAssignmentDisposable
@@ -8,10 +8,10 @@ from reactivex.scheduler.periodicscheduler import PeriodicScheduler
8
8
 
9
9
 
10
10
  def observable_timer_date(
11
- duetime: typing.AbsoluteTime, scheduler: Optional[abc.SchedulerBase] = None
11
+ duetime: typing.AbsoluteTime, scheduler: abc.SchedulerBase | None = None
12
12
  ) -> Observable[int]:
13
13
  def subscribe(
14
- observer: abc.ObserverBase[int], scheduler_: Optional[abc.SchedulerBase] = None
14
+ observer: abc.ObserverBase[int], scheduler_: abc.SchedulerBase | None = None
15
15
  ) -> abc.DisposableBase:
16
16
  _scheduler: abc.SchedulerBase = (
17
17
  scheduler or scheduler_ or TimeoutScheduler.singleton()
@@ -29,10 +29,10 @@ def observable_timer_date(
29
29
  def observable_timer_duetime_and_period(
30
30
  duetime: typing.AbsoluteOrRelativeTime,
31
31
  period: typing.AbsoluteOrRelativeTime,
32
- scheduler: Optional[abc.SchedulerBase] = None,
32
+ scheduler: abc.SchedulerBase | None = None,
33
33
  ) -> Observable[int]:
34
34
  def subscribe(
35
- observer: abc.ObserverBase[int], scheduler_: Optional[abc.SchedulerBase] = None
35
+ observer: abc.ObserverBase[int], scheduler_: abc.SchedulerBase | None = None
36
36
  ) -> abc.DisposableBase:
37
37
  _scheduler = scheduler or scheduler_ or TimeoutScheduler.singleton()
38
38
  nonlocal duetime
@@ -66,10 +66,10 @@ def observable_timer_duetime_and_period(
66
66
 
67
67
 
68
68
  def observable_timer_timespan(
69
- duetime: typing.RelativeTime, scheduler: Optional[abc.SchedulerBase] = None
69
+ duetime: typing.RelativeTime, scheduler: abc.SchedulerBase | None = None
70
70
  ) -> Observable[int]:
71
71
  def subscribe(
72
- observer: abc.ObserverBase[int], scheduler_: Optional[abc.SchedulerBase] = None
72
+ observer: abc.ObserverBase[int], scheduler_: abc.SchedulerBase | None = None
73
73
  ) -> abc.DisposableBase:
74
74
  _scheduler = scheduler or scheduler_ or TimeoutScheduler.singleton()
75
75
  d = _scheduler.to_seconds(duetime)
@@ -88,19 +88,19 @@ def observable_timer_timespan(
88
88
  def observable_timer_timespan_and_period(
89
89
  duetime: typing.RelativeTime,
90
90
  period: typing.RelativeTime,
91
- scheduler: Optional[abc.SchedulerBase] = None,
91
+ scheduler: abc.SchedulerBase | None = None,
92
92
  ) -> Observable[int]:
93
93
  if duetime == period:
94
94
 
95
95
  def subscribe(
96
96
  observer: abc.ObserverBase[int],
97
- scheduler_: Optional[abc.SchedulerBase] = None,
97
+ scheduler_: abc.SchedulerBase | None = None,
98
98
  ) -> abc.DisposableBase:
99
99
  _scheduler: abc.SchedulerBase = (
100
100
  scheduler or scheduler_ or TimeoutScheduler.singleton()
101
101
  )
102
102
 
103
- def action(count: Optional[int] = None) -> Optional[int]:
103
+ def action(count: int | None = None) -> int | None:
104
104
  if count is not None:
105
105
  observer.on_next(count)
106
106
  return count + 1
@@ -116,8 +116,8 @@ def observable_timer_timespan_and_period(
116
116
 
117
117
  def timer_(
118
118
  duetime: typing.AbsoluteOrRelativeTime,
119
- period: Optional[typing.RelativeTime] = None,
120
- scheduler: Optional[abc.SchedulerBase] = None,
119
+ period: typing.RelativeTime | None = None,
120
+ scheduler: abc.SchedulerBase | None = None,
121
121
  ) -> Observable[int]:
122
122
  if isinstance(duetime, datetime):
123
123
  if period is None:
@@ -1,4 +1,5 @@
1
- from typing import Any, Callable, Optional, TypeVar
1
+ from collections.abc import Callable
2
+ from typing import Any, TypeVar
2
3
 
3
4
  from reactivex import Observable, abc
4
5
  from reactivex import operators as ops
@@ -9,7 +10,7 @@ _T = TypeVar("_T")
9
10
 
10
11
 
11
12
  def to_async_(
12
- func: Callable[..., _T], scheduler: Optional[abc.SchedulerBase] = None
13
+ func: Callable[..., _T], scheduler: abc.SchedulerBase | None = None
13
14
  ) -> Callable[..., Observable[_T]]:
14
15
  """Converts the function into an asynchronous function. Each
15
16
  invocation of the resulting asynchronous function causes an
@@ -1,4 +1,5 @@
1
- from typing import Callable, Optional, TypeVar
1
+ from collections.abc import Callable
2
+ from typing import TypeVar
2
3
 
3
4
  import reactivex
4
5
  from reactivex import Observable, abc
@@ -8,8 +9,8 @@ _T = TypeVar("_T")
8
9
 
9
10
 
10
11
  def using_(
11
- resource_factory: Callable[[], Optional[abc.DisposableBase]],
12
- observable_factory: Callable[[Optional[abc.DisposableBase]], Observable[_T]],
12
+ resource_factory: Callable[[], abc.DisposableBase | None],
13
+ observable_factory: Callable[[abc.DisposableBase | None], Observable[_T]],
13
14
  ) -> Observable[_T]:
14
15
  """Constructs an observable sequence that depends on a resource
15
16
  object, whose lifetime is tied to the resulting observable
@@ -29,7 +30,7 @@ def using_(
29
30
  """
30
31
 
31
32
  def subscribe(
32
- observer: abc.ObserverBase[_T], scheduler: Optional[abc.SchedulerBase] = None
33
+ observer: abc.ObserverBase[_T], scheduler: abc.SchedulerBase | None = None
33
34
  ) -> abc.DisposableBase:
34
35
  disp: abc.DisposableBase = Disposable()
35
36
 
@@ -1,4 +1,4 @@
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
@@ -7,16 +7,15 @@ from reactivex.internal.utils import NotSet
7
7
 
8
8
  def with_latest_from_(
9
9
  parent: Observable[Any], *sources: Observable[Any]
10
- ) -> Observable[Tuple[Any, ...]]:
10
+ ) -> Observable[tuple[Any, ...]]:
11
11
  NO_VALUE = NotSet()
12
12
 
13
13
  def subscribe(
14
- observer: abc.ObserverBase[Any], scheduler: Optional[abc.SchedulerBase] = None
14
+ observer: abc.ObserverBase[Any], scheduler: abc.SchedulerBase | None = None
15
15
  ) -> abc.DisposableBase:
16
16
  def subscribeall(
17
17
  parent: Observable[Any], *children: Observable[Any]
18
- ) -> List[SingleAssignmentDisposable]:
19
-
18
+ ) -> list[SingleAssignmentDisposable]:
20
19
  values = [NO_VALUE for _ in children]
21
20
 
22
21
  def subscribechild(
@@ -1,13 +1,13 @@
1
1
  from asyncio import Future
2
2
  from threading import RLock
3
- from typing import Any, List, Optional, Tuple
3
+ from typing import Any, cast
4
4
 
5
5
  from reactivex import Observable, abc, from_future
6
6
  from reactivex.disposable import CompositeDisposable, SingleAssignmentDisposable
7
7
  from reactivex.internal import synchronized
8
8
 
9
9
 
10
- def zip_(*args: Observable[Any]) -> Observable[Tuple[Any, ...]]:
10
+ def zip_(*args: Observable[Any]) -> Observable[tuple[Any, ...]]:
11
11
  """Merges the specified observable sequences into one observable
12
12
  sequence by creating a tuple whenever all of the
13
13
  observable sequences have produced an element at a corresponding
@@ -27,10 +27,10 @@ def zip_(*args: Observable[Any]) -> Observable[Tuple[Any, ...]]:
27
27
  sources = list(args)
28
28
 
29
29
  def subscribe(
30
- observer: abc.ObserverBase[Any], scheduler: Optional[abc.SchedulerBase] = None
30
+ observer: abc.ObserverBase[Any], scheduler: abc.SchedulerBase | None = None
31
31
  ) -> CompositeDisposable:
32
32
  n = len(sources)
33
- queues: List[List[Any]] = [[] for _ in range(n)]
33
+ queues: list[list[Any]] = [[] for _ in range(n)]
34
34
  lock = RLock()
35
35
  is_completed = [False] * n
36
36
 
@@ -62,12 +62,13 @@ def zip_(*args: Observable[Any]) -> Observable[Tuple[Any, ...]]:
62
62
  if len(queues[i]) == 0:
63
63
  observer.on_completed()
64
64
 
65
- subscriptions: List[Optional[abc.DisposableBase]] = [None] * n
65
+ subscriptions: list[abc.DisposableBase | None] = [None] * n
66
66
 
67
67
  def func(i: int) -> None:
68
68
  source: Observable[Any] = sources[i]
69
69
  if isinstance(source, Future):
70
- source = from_future(source)
70
+ source_ = cast(Future[Any], source)
71
+ source = from_future(source_)
71
72
 
72
73
  sad = SingleAssignmentDisposable()
73
74
 
@@ -1,4 +1,4 @@
1
- from typing import Optional, TypeVar
1
+ from typing import TypeVar
2
2
 
3
3
  from reactivex.disposable import SingleAssignmentDisposable
4
4
  from reactivex.internal import default_error, noop
@@ -11,9 +11,9 @@ _T_in = TypeVar("_T_in", contravariant=True)
11
11
  class AutoDetachObserver(abc.ObserverBase[_T_in]):
12
12
  def __init__(
13
13
  self,
14
- on_next: Optional[typing.OnNext[_T_in]] = None,
15
- on_error: Optional[typing.OnError] = None,
16
- on_completed: Optional[typing.OnCompleted] = None,
14
+ on_next: typing.OnNext[_T_in] | None = None,
15
+ on_error: typing.OnError | None = None,
16
+ on_completed: typing.OnCompleted | None = None,
17
17
  ) -> None:
18
18
  self._on_next = on_next or noop
19
19
  self._on_error = on_error or default_error
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING, Callable, Optional, TypeVar
3
+ from collections.abc import Callable
4
+ from typing import TYPE_CHECKING, TypeVar
4
5
 
5
6
  from reactivex import abc
6
7
  from reactivex.internal.basic import default_error, noop
@@ -24,9 +25,9 @@ class Observer(abc.ObserverBase[_T_in], abc.DisposableBase):
24
25
 
25
26
  def __init__(
26
27
  self,
27
- on_next: Optional[OnNext[_T_in]] = None,
28
- on_error: Optional[OnError] = None,
29
- on_completed: Optional[OnCompleted] = None,
28
+ on_next: OnNext[_T_in] | None = None,
29
+ on_error: OnError | None = None,
30
+ on_completed: OnCompleted | None = None,
30
31
  ) -> None:
31
32
  self.is_stopped = False
32
33
  self._handler_on_next: OnNext[_T_in] = on_next or noop
@@ -1,5 +1,5 @@
1
1
  import threading
2
- from typing import Any, List, TypeVar
2
+ from typing import Any, TypeVar
3
3
 
4
4
  from reactivex import abc, typing
5
5
  from reactivex.disposable import SerialDisposable
@@ -21,7 +21,7 @@ class ScheduledObserver(Observer[_T_in]):
21
21
  self.lock = threading.RLock()
22
22
  self.is_acquired = False
23
23
  self.has_faulted = False
24
- self.queue: List[typing.Action] = []
24
+ self.queue: list[typing.Action] = []
25
25
  self.disposable = SerialDisposable()
26
26
 
27
27
  # Note to self: list append is thread safe