Skip to content

Commit 8413154

Browse files
github-actions[bot]Copilotdbrattliclaude
authored
test: fix pyright strict-mode errors in tests/test_observable/ (batch 3) (#785)
* test: fix pyright strict-mode errors in tests/test_observable/ (batch 3) Fix pyright errors in 25 test files in tests/test_observable/: - Add 'from typing import NoReturn' import - Annotate '_raise' functions with 'ex: Exception -> NoReturn' signature - Fix callsites passing str to '_raise()' to wrap in Exception() - Fix subscribe functions returning 'lambda: None' to return Disposable() - Fix 'return dispose' to 'return Disposable(dispose)' - Fix 'o.on_error(str)' calls to wrap strings in Exception() - Fix 'do_action(on_next=action)' with zero-param action to accept one param - Remove non-None return values from 'finally_action' callbacks These changes allow tests/test_observable/ to eventually be removed from the pyright exclude list in pyproject.toml. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger build * style: fix ruff import order and line length in test_observable batch 3 Pre-commit hook failures from PR #785: - Reorder `from typing import NoReturn` after `from datetime` in 3 files - Wrap two long lines exceeding 88 chars in test_fromiterable.py and test_minby.py Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Dag Brattli <dag@brattli.net> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2da73b4 commit 8413154

25 files changed

Lines changed: 76 additions & 52 deletions

tests/test_observable/test_bufferwithcount.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from typing import NoReturn
23

34
from reactivex import operators as ops
45
from reactivex.testing import ReactiveTest, TestScheduler
@@ -17,7 +18,7 @@ class RxException(Exception):
1718

1819

1920
# Helper function for raising exceptions within lambdas
20-
def _raise(ex):
21+
def _raise(ex: Exception) -> NoReturn:
2122
raise RxException(ex)
2223

2324

tests/test_observable/test_create.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import unittest
2+
from typing import NoReturn
23

34
import reactivex
5+
from reactivex.disposable import Disposable
46
from reactivex.testing import ReactiveTest, TestScheduler
57

68
on_next = ReactiveTest.on_next
@@ -17,7 +19,7 @@ class RxException(Exception):
1719

1820

1921
# Helper function for raising exceptions within lambdas
20-
def _raise(ex):
22+
def _raise(ex: str) -> NoReturn:
2123
raise RxException(ex)
2224

2325

@@ -29,7 +31,7 @@ def _create():
2931
def subscribe(o, scheduler=None):
3032
o.on_next(1)
3133
o.on_next(2)
32-
return lambda: None
34+
return Disposable()
3335

3436
return reactivex.create(subscribe)
3537

@@ -43,9 +45,9 @@ def _create():
4345
def subscribe(o, scheduler=None):
4446
o.on_completed()
4547
o.on_next(100)
46-
o.on_error("ex")
48+
o.on_error(Exception("ex"))
4749
o.on_completed()
48-
return lambda: None
50+
return Disposable()
4951

5052
return reactivex.create(subscribe)
5153

@@ -58,11 +60,11 @@ def test_create_error(self):
5860

5961
def _create():
6062
def subscribe(o, scheduler=None):
61-
o.on_error(ex)
63+
o.on_error(Exception(ex))
6264
o.on_next(100)
63-
o.on_error("foo")
65+
o.on_error(Exception("foo"))
6466
o.on_completed()
65-
return lambda: None
67+
return Disposable()
6668

6769
return reactivex.create(subscribe)
6870

@@ -109,7 +111,7 @@ def action4(scheduler, state):
109111
def dispose():
110112
is_stopped[0] = True
111113

112-
return dispose
114+
return Disposable(dispose)
113115

114116
return reactivex.create(subscribe)
115117

@@ -124,21 +126,21 @@ def dispose():
124126
def test_create_observer_throws(self):
125127
def subscribe(o, scheduler=None):
126128
o.on_next(1)
127-
return lambda: None
129+
return Disposable()
128130

129131
with self.assertRaises(RxException):
130132
reactivex.create(subscribe).subscribe(lambda x: _raise("ex"))
131133

132134
def subscribe2(o, scheduler=None):
133-
o.on_error("exception")
134-
return lambda: None
135+
o.on_error(Exception("exception"))
136+
return Disposable()
135137

136138
with self.assertRaises(RxException):
137139
reactivex.create(subscribe2).subscribe(on_error=lambda ex: _raise("ex"))
138140

139141
def subscribe3(o, scheduler=None):
140142
o.on_completed()
141-
return lambda: None
143+
return Disposable()
142144

143145
with self.assertRaises(RxException):
144146
reactivex.create(subscribe3).subscribe(on_completed=lambda: _raise("ex"))

tests/test_observable/test_debounce.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from typing import NoReturn
23

34
from reactivex import empty, never, throw
45
from reactivex import operators as _
@@ -18,7 +19,7 @@ class RxException(Exception):
1819

1920

2021
# Helper function for raising exceptions within lambdas
21-
def _raise(ex):
22+
def _raise(ex: Exception) -> NoReturn:
2223
raise RxException(ex)
2324

2425

tests/test_observable/test_defer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from typing import NoReturn
23

34
import reactivex
45
from reactivex.testing import ReactiveTest, TestScheduler
@@ -18,7 +19,7 @@ class RxException(Exception):
1819

1920

2021
# Helper function for raising exceptions within lambdas
21-
def _raise(ex):
22+
def _raise(ex: Exception) -> NoReturn:
2223
raise RxException(ex)
2324

2425

tests/test_observable/test_delay.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import unittest
33
from datetime import datetime, timezone
4+
from typing import NoReturn
45

56
from reactivex.operators import delay
67
from reactivex.testing import ReactiveTest, TestScheduler
@@ -23,7 +24,7 @@ class RxException(Exception):
2324

2425

2526
# Helper function for raising exceptions within lambdas
26-
def _raise(ex):
27+
def _raise(ex: Exception) -> NoReturn:
2728
raise RxException(ex)
2829

2930

tests/test_observable/test_delaywithmapper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from typing import NoReturn
23

34
from reactivex import Observable, abc
45
from reactivex import operators as ops
@@ -20,7 +21,7 @@ class RxException(Exception):
2021

2122

2223
# Helper function for raising exceptions within lambdas
23-
def _raise(ex):
24+
def _raise(ex: Exception) -> NoReturn:
2425
raise RxException(ex)
2526

2627

tests/test_observable/test_distinct.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22
import unittest
3+
from typing import NoReturn
34

45
from reactivex import operators as ops
56
from reactivex.testing import ReactiveTest, TestScheduler
@@ -18,7 +19,7 @@ class RxException(Exception):
1819

1920

2021
# Helper function for raising exceptions within lambdas
21-
def _raise(ex):
22+
def _raise(ex: Exception) -> NoReturn:
2223
raise RxException(ex)
2324

2425

tests/test_observable/test_distinctuntilchanged.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from typing import NoReturn
23

34
import reactivex
45
from reactivex import operators as ops
@@ -18,7 +19,7 @@ class RxException(Exception):
1819

1920

2021
# Helper function for raising exceptions within lambdas
21-
def _raise(ex):
22+
def _raise(ex: Exception) -> NoReturn:
2223
raise RxException(ex)
2324

2425

@@ -282,7 +283,7 @@ def test_distinct_until_changed_key_mapper_throws(self):
282283
)
283284

284285
def create():
285-
return xs.pipe(ops.distinct_until_changed(lambda x: _raise(ex)))
286+
return xs.pipe(ops.distinct_until_changed(lambda x: _raise(Exception(ex))))
286287

287288
results = scheduler.start(create)
288289
assert results.messages == [on_error(210, ex)]
@@ -296,7 +297,7 @@ def test_distinct_until_changed_comparer_throws(self):
296297

297298
def create():
298299
return xs.pipe(
299-
ops.distinct_until_changed(comparer=lambda x, y: _raise(ex)),
300+
ops.distinct_until_changed(comparer=lambda x, y: _raise(Exception(ex))),
300301
)
301302

302303
results = scheduler.start(create)

tests/test_observable/test_expand.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from typing import NoReturn
23

34
from reactivex import operators as ops
45
from reactivex.testing import ReactiveTest, TestScheduler
@@ -17,7 +18,7 @@ class RxException(Exception):
1718

1819

1920
# Helper function for raising exceptions within lambdas
20-
def _raise(ex):
21+
def _raise(ex: Exception) -> NoReturn:
2122
raise RxException(ex)
2223

2324

tests/test_observable/test_finally.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def test_finally_only_called_once_empty(self):
1919

2020
def action():
2121
invasserte_count[0] += 1
22-
return invasserte_count
2322

2423
some_observable = reactivex.empty().pipe(ops.finally_action(action))
2524

@@ -36,7 +35,6 @@ def test_finally_empty(self):
3635
def create():
3736
def action():
3837
invasserted[0] = True
39-
return invasserted[0]
4038

4139
return xs.pipe(ops.finally_action(action))
4240

@@ -55,7 +53,6 @@ def test_finally_return(self):
5553
def create():
5654
def action():
5755
invasserted[0] = True
58-
return invasserted[0]
5956

6057
return xs.pipe(ops.finally_action(action))
6158

@@ -78,7 +75,6 @@ def test_finally_on_error(self):
7875
def create():
7976
def action():
8077
invasserted[0] = True
81-
return invasserted[0]
8278

8379
return xs.pipe(ops.finally_action(action))
8480

0 commit comments

Comments
 (0)