Skip to content

Commit 37534d0

Browse files
committed
#223-remove Pylance warnings
Intermediate commit. Fully validated on base classes.
1 parent c8953d4 commit 37534d0

30 files changed

+830
-806
lines changed

Python3.10/unit_tests/test_basemrg.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@
2929

3030
#=============================================================================
3131
class TestBaseMRG:
32-
"""Tests the base class BaseMRG"""
32+
"""Tests the base class BaseMRG.
33+
"""
3334

3435

3536
#-------------------------------------------------------------------------
3637
def test_init0(self):
3738
b_mrg = BaseMRG(SplitMix31)
3839
assert b_mrg._initRandClass is SplitMix31
39-
assert b_mrg.gauss_next is None
40+
assert b_mrg.gauss_next is None # type: ignore
4041
assert b_mrg._index == 0
4142
assert b_mrg._NORMALIZE == 1.0 / (1 << 32) # should be (1 << 31), but not set after construction of base class BaseMRG
4243
assert b_mrg._OUT_BITS == 32 # should be 31, but not set after construction of base class BaseMRG
@@ -49,7 +50,7 @@ def test_init_empty(self):
4950
b_mrg = BaseMRG(SplitMix31, STATE_SIZE)
5051
assert b_mrg._STATE_SIZE == STATE_SIZE
5152
assert b_mrg._initRandClass is SplitMix31
52-
assert b_mrg.gauss_next is None
53+
assert b_mrg.gauss_next is None # type: ignore
5354
assert b_mrg._index == 0
5455
assert len(b_mrg._state) == STATE_SIZE
5556
assert all(s != 0 for s in b_mrg._state)
@@ -64,7 +65,7 @@ def test_init_int(self):
6465
b_mrg = BaseMRG(SplitMix32, STATE_SIZE, 0X1234_5678_9abc_def0)
6566
assert b_mrg._STATE_SIZE == STATE_SIZE
6667
assert b_mrg._initRandClass is SplitMix32
67-
assert b_mrg.gauss_next is None
68+
assert b_mrg.gauss_next is None # type: ignore
6869
assert b_mrg._index == 0
6970
assert len(b_mrg._state) == STATE_SIZE
7071
assert all(s != 0 for s in b_mrg._state)
@@ -79,7 +80,7 @@ def test_init_float(self):
7980
b_mrg = BaseMRG(SplitMix31, STATE_SIZE, 0.1)
8081
assert b_mrg._STATE_SIZE == STATE_SIZE
8182
assert b_mrg._initRandClass is SplitMix31
82-
assert b_mrg.gauss_next is None
83+
assert b_mrg.gauss_next is None # type: ignore
8384
assert b_mrg._index == 0
8485
assert len(b_mrg._state) == STATE_SIZE
8586
assert all(s != 0 for s in b_mrg._state)
@@ -91,10 +92,10 @@ def test_init_tuple(self):
9192
STATE_SIZE = 19
9293
with pytest.raises(TypeError):
9394
# notice: no 2 arguments accepted in tuple with base class random.Random constructor until Python 3.11
94-
b_mrg = BaseMRG(SplitMix32, STATE_SIZE, tuple(i+1 for i in range(STATE_SIZE)))
95+
b_mrg = BaseMRG(SplitMix32, STATE_SIZE, tuple(i+1 for i in range(STATE_SIZE))) # type: ignore
9596
assert b_mrg._STATE_SIZE == STATE_SIZE
9697
assert b_mrg._initRandClass is SplitMix32
97-
assert b_mrg.gauss_next is None
98+
assert b_mrg.gauss_next is None # type: ignore
9899
assert b_mrg._index == 0
99100
assert len(b_mrg._state) == STATE_SIZE
100101
assert all(s != 0 for s in b_mrg._state)
@@ -109,7 +110,7 @@ def test_init_list(self):
109110
b_mrg = BaseMRG(SplitMix31, STATE_SIZE, [i+1 for i in range(STATE_SIZE)])
110111
assert b_mrg._STATE_SIZE == STATE_SIZE
111112
assert b_mrg._initRandClass is SplitMix31
112-
assert b_mrg.gauss_next is None
113+
assert b_mrg.gauss_next is None # type: ignore
113114
assert b_mrg._index == 0
114115
assert len(b_mrg._state) == STATE_SIZE
115116
assert all(s != 0 for s in b_mrg._state)
@@ -121,11 +122,11 @@ def test_init_tuple_int(self):
121122
STATE_SIZE = 23
122123
with pytest.raises(TypeError):
123124
# notice: no 2 arguments accepted in tuple with base class random.Random constructor since Python 3.9
124-
b_mrg = BaseMRG(SplitMix32, STATE_SIZE, tuple(STATE_SIZE-1, tuple(i+1 for i in range(STATE_SIZE))))
125+
b_mrg = BaseMRG(SplitMix32, STATE_SIZE, tuple(STATE_SIZE-1, tuple(i+1 for i in range(STATE_SIZE)))) # type: ignore
125126

126127
#-------------------------------------------------------------------------
127128
def test_init_list_int(self):
128129
STATE_SIZE = 25
129130
with pytest.raises(TypeError):
130131
# notice: no 2 arguments accepted in tuple with base class random.Random constructor since Python 3.9
131-
b_mrg = BaseMRG( SplitMix31, STATE_SIZE, tuple(STATE_SIZE-1, [i+1 for i in range(STATE_SIZE)]) )
132+
b_mrg = BaseMRG( SplitMix31, STATE_SIZE, tuple(STATE_SIZE-1, [i+1 for i in range(STATE_SIZE)]) ) # type: ignore

Python3.10/unit_tests/test_basepcg.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ class TestBasePcg:
3333
#-------------------------------------------------------------------------
3434
def test_init_empty(self):
3535
b_pcg = BasePCG()
36-
assert b_pcg.gauss_next is None
36+
assert b_pcg.gauss_next is None # type: ignore
3737

3838
#-------------------------------------------------------------------------
3939
def test_init_int(self):
4040
b_pcg = BasePCG(0X1234_5678_9abc_def0)
41-
assert b_pcg.gauss_next is None
41+
assert b_pcg.gauss_next is None # type: ignore
4242

4343
#-------------------------------------------------------------------------
4444
def test_init_float(self):
4545
b_pcg = BasePCG(0.1)
46-
assert b_pcg.gauss_next is None
46+
assert b_pcg.gauss_next is None # type: ignore
4747

4848
#-------------------------------------------------------------------------
4949
def test_init_tuple(self):
5050
with pytest.raises(NotImplementedError):
51-
b_pcg = BasePCG((0, 1, 0X1234_5678_9abc_def0, 0X1234_5678_9abc_def0))
51+
b_pcg = BasePCG((0, 1, 0X1234_5678_9abc_def0, 0X1234_5678_9abc_def0)) # type: ignore
5252

5353
#-------------------------------------------------------------------------
5454
def test_init_list(self):
@@ -58,7 +58,7 @@ def test_init_list(self):
5858
#-------------------------------------------------------------------------
5959
def test_init_tuple_int(self):
6060
with pytest.raises(NotImplementedError):
61-
b_pcg = BasePCG( ((0, 1, 0X1234_5678_9abc_def0, 0X1234_5678_9abc_def0), 11) )
61+
b_pcg = BasePCG( ((0, 1, 0X1234_5678_9abc_def0, 0X1234_5678_9abc_def0), 11) ) # type: ignore
6262

6363
#-------------------------------------------------------------------------
6464
def test_init_list_int(self):
@@ -68,12 +68,12 @@ def test_init_list_int(self):
6868
#-------------------------------------------------------------------------
6969
def test_init_tuple_int_2(self):
7070
with pytest.raises(TypeError): # notice: TypeError here due to a known bug with unhashable lists in Python 3.10
71-
b_pcg = BasePCG( [(0, 1, 0X1234_5678_9abc_def0, 0X1234_5678_9abc_def0), 11] )
71+
b_pcg = BasePCG( [(0, 1, 0X1234_5678_9abc_def0, 0X1234_5678_9abc_def0), 11] ) # type: ignore
7272

7373
#-------------------------------------------------------------------------
7474
def test_init_list_int_2(self):
7575
with pytest.raises(TypeError): # notice: TypeError here due to a known bug with unhashable lists in Python 3.10
76-
b_pcg = BasePCG( [[0, 1, 0X1234_5678_9abc_def0, 0X1234_5678_9abc_def0], 11] )
76+
b_pcg = BasePCG( [[0, 1, 0X1234_5678_9abc_def0, 0X1234_5678_9abc_def0], 11] ) # type: ignore
7777

7878
#-------------------------------------------------------------------------
7979
def test_getstate(self):

Python3.10/unit_tests/test_basesquares.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828

2929
#=============================================================================
3030
class TestBaseSquares:
31-
"""Tests the base class BaseSquares"""
31+
"""Tests the base class BaseSquares.
32+
"""
3233

3334
#-------------------------------------------------------------------------
3435
def test_init_empty(self):
3536
b_sqr = BaseSquares()
36-
assert b_sqr.gauss_next is None
37+
assert b_sqr.gauss_next is None # type: ignore
3738
assert b_sqr._counter == 0
3839
assert b_sqr._key & 1 == 1
3940
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
@@ -42,7 +43,7 @@ def test_init_empty(self):
4243
#-------------------------------------------------------------------------
4344
def test_init_int(self):
4445
b_sqr = BaseSquares(0x0123_4567_89ab_cdef)
45-
assert b_sqr.gauss_next is None
46+
assert b_sqr.gauss_next is None # type: ignore
4647
assert b_sqr._counter == 0
4748
assert b_sqr._key & 1 == 1
4849
assert b_sqr._key == 0x2c38_1b75_cd1e_96f3
@@ -53,7 +54,7 @@ def test_init_int(self):
5354
def test_init_float(self):
5455
STATE_SIZE = 17
5556
b_sqr = BaseSquares(0.357)
56-
assert b_sqr.gauss_next is None
57+
assert b_sqr.gauss_next is None # type: ignore
5758
assert b_sqr._counter == 0
5859
assert b_sqr._key == 0x69ef_8b1a_6eda_9b27
5960
assert b_sqr._NORMALIZE == 1.0 / (1 << 32) # should be (1 << 31), but not set after construction of base class BaseSquares
@@ -66,23 +67,23 @@ def test_init_float(self):
6667

6768
#-------------------------------------------------------------------------
6869
def test_init_tuple(self):
69-
b_sqr = BaseSquares((21, 160,))
70-
assert b_sqr.gauss_next is None
70+
b_sqr = BaseSquares((21, 160,)) # type: ignore
71+
assert b_sqr.gauss_next is None # type: ignore
7172
assert b_sqr._counter == 21
7273
assert b_sqr._key == 161 # i.e. 160 | 1
7374
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
7475
assert b_sqr._OUT_BITS == 32
7576

7677
with pytest.raises(ValueError):
77-
b_sqr = BaseSquares((21, 160, 3))
78+
b_sqr = BaseSquares((21, 160, 3)) # type: ignore
7879
with pytest.raises(ValueError):
7980
b_sqr = BaseSquares((21,))
8081

8182
#-------------------------------------------------------------------------
8283
def test_init_list(self):
8384
with pytest.raises(TypeError): # notice: TypeError here due to a known bug with unhashable lists in Python 3.10
8485
b_sqr = BaseSquares([23, 162])
85-
assert b_sqr.gauss_next is None
86+
assert b_sqr.gauss_next is None # type: ignore
8687
assert b_sqr._counter == 23
8788
assert b_sqr._key == 163 # i.e. 162 | 1
8889
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
@@ -99,7 +100,7 @@ def test_init_list(self):
99100
def test_init_tuple_int(self):
100101
with pytest.raises(ValueError):
101102
# notice: no 2 arguments accepted in tuple with base class random.Random constructor since Python 3.11
102-
b_sqr = BaseSquares(((21, 161,), 11))
103+
b_sqr = BaseSquares(((21, 161,), 11)) # type: ignore
103104

104105
#-------------------------------------------------------------------------
105106
def test_init_list_int(self):
@@ -108,13 +109,13 @@ def test_init_list_int(self):
108109

109110
#-------------------------------------------------------------------------
110111
def test_getstate(self):
111-
b_sqr = BaseSquares((23, 163))
112-
counter, key = b_sqr.getstate()
112+
b_sqr = BaseSquares((23, 163)) # type: ignore
113+
counter, key = b_sqr.getstate() # type: ignore
113114
assert counter == b_sqr._counter
114115
assert key == b_sqr._key
115116
assert counter == 23
116117
assert key == 163
117-
assert b_sqr.gauss_next is None
118+
assert b_sqr.gauss_next is None # type: ignore
118119
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
119120
assert b_sqr._OUT_BITS == 32
120121

@@ -125,61 +126,61 @@ def test_seed(self):
125126
b_sqr.seed()
126127
assert b_sqr._counter == 0
127128
assert b_sqr._key & 1 == 1
128-
assert b_sqr.gauss_next is None
129+
assert b_sqr.gauss_next is None # type: ignore
129130
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
130131
assert b_sqr._OUT_BITS == 32
131132

132133
b_sqr.seed(0x0123_4567_89ab_cdef)
133134
assert b_sqr._counter == 0
134135
assert b_sqr._key == 0x2c38_1b75_cd1e_96f3
135-
assert b_sqr.gauss_next is None
136+
assert b_sqr.gauss_next is None # type: ignore
136137
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
137138
assert b_sqr._OUT_BITS == 32
138139

139140
b_sqr.seed(-8_870_000_000_000_000_000)
140141
assert b_sqr._counter == 0
141142
assert b_sqr._key == 0x5d7f_2468_39ae_54f3
142-
assert b_sqr.gauss_next is None
143+
assert b_sqr.gauss_next is None # type: ignore
143144
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
144145
assert b_sqr._OUT_BITS
145146

146147
b_sqr.seed(8_870_000_000_000_000_000)
147148
assert b_sqr._counter == 0
148149
assert b_sqr._key == 0xea49_fd18_2c19_435d
149-
assert b_sqr.gauss_next is None
150+
assert b_sqr.gauss_next is None # type: ignore
150151
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
151152
assert b_sqr._OUT_BITS
152153

153154
b_sqr.seed(0.357)
154155
assert b_sqr._counter == 0
155156
assert b_sqr._key == 0x69ef_8b1a_6eda_9b27
156-
assert b_sqr.gauss_next is None
157+
assert b_sqr.gauss_next is None # type: ignore
157158
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
158159
assert b_sqr._OUT_BITS
159160

160161
b_sqr.seed(0xfedc_ba98_7654_3210_0123_4567_89ab_cdef)
161162
assert b_sqr._counter == 0
162163
assert b_sqr._key == 0x2c38_1b75_cd1e_96f3
163-
assert b_sqr.gauss_next is None
164+
assert b_sqr.gauss_next is None # type: ignore
164165
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
165166
assert b_sqr._OUT_BITS
166167

167168
with pytest.raises(TypeError):
168-
b_sqr.seed((1, 2))
169+
b_sqr.seed((1, 2)) # type: ignore
169170
with pytest.raises(TypeError):
170171
b_sqr.seed([11, 12])
171172
with pytest.raises(TypeError):
172173
b_sqr.seed([21, 22, 23])
173174
with pytest.raises(TypeError):
174-
b_sqr.seed((31, 32, 33, 34))
175+
b_sqr.seed((31, 32, 33, 34)) # type: ignore
175176
with pytest.raises(ValueError):
176177
b_sqr.seed(-0.1)
177178
with pytest.raises(ValueError):
178179
b_sqr.seed(1.0001)
179180
with pytest.raises(TypeError):
180-
b_sqr.seed([31, 32.1])
181+
b_sqr.seed([31, 32.1]) # type: ignore
181182
with pytest.raises(TypeError):
182-
b_sqr.seed((34, 35.1))
183+
b_sqr.seed((34, 35.1)) # type: ignore
183184

184185
#-------------------------------------------------------------------------
185186
def test_setstate(self):
@@ -188,38 +189,38 @@ def test_setstate(self):
188189
b_sqr.setstate()
189190
assert b_sqr._counter == 0
190191
assert b_sqr._key & 1 == 1
191-
assert b_sqr.gauss_next is None
192+
assert b_sqr.gauss_next is None # type: ignore
192193
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
193194
assert b_sqr._OUT_BITS == 32
194195

195-
b_sqr.setstate((1, 2))
196+
b_sqr.setstate((1, 2)) # type: ignore
196197
assert b_sqr._counter == 1
197198
assert b_sqr._key == 2 | 1
198-
assert b_sqr.gauss_next is None
199+
assert b_sqr.gauss_next is None # type: ignore
199200
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
200201
assert b_sqr._OUT_BITS
201202

202203
b_sqr.setstate([11, 12])
203204
assert b_sqr._counter == 11
204205
assert b_sqr._key == 12 | 1
205-
assert b_sqr.gauss_next is None
206+
assert b_sqr.gauss_next is None # type: ignore
206207
assert b_sqr._NORMALIZE == 1.0 / (1 << 32)
207208
assert b_sqr._OUT_BITS
208209

209210
with pytest.raises(TypeError):
210-
b_sqr.setstate(-0.1)
211+
b_sqr.setstate(-0.1) # type: ignore
211212
with pytest.raises(TypeError):
212-
b_sqr.setstate(1.0001)
213+
b_sqr.setstate(1.0001) # type: ignore
213214
with pytest.raises(ValueError):
214-
b_sqr.setstate([31, 32.1])
215+
b_sqr.setstate([31, 32.1]) # type: ignore
215216
with pytest.raises(ValueError):
216-
b_sqr.setstate((34, 35.1))
217+
b_sqr.setstate((34, 35.1)) # type: ignore
217218

218219
#-------------------------------------------------------------------------
219220
def test__initkey(self):
220221
b_sqr = BaseSquares()
221222
assert b_sqr._initKey(0x0123_4567_89ab_cdef) == 0x2c38_1b75_cd1e_96f3
222223
assert b_sqr._initKey(-8_870_000_000_000_000_000) == 0x5d7f_2468_39ae_54f3
223224
assert b_sqr._initKey(8_870_000_000_000_000_000) == 0xea49_fd18_2c19_435d
224-
assert b_sqr._initKey(0.357) == 0x69ef_8b1a_6eda_9b27
225+
assert b_sqr._initKey(0.357) == 0x69ef_8b1a_6eda_9b27 # type: ignore
225226
assert b_sqr._initKey(0xfedc_ba98_7654_3210_0123_4567_89ab_cdef) == 0x2c38_1b75_cd1e_96f3

0 commit comments

Comments
 (0)