|
16 | 16 | from hypothesistooling.projects.hypothesispython import PYTHON_SRC
|
17 | 17 | from hypothesistooling.scripts import pip_tool, tool_path
|
18 | 18 |
|
| 19 | +from .revealed_types import NUMPY_REVEALED_TYPES |
| 20 | + |
19 | 21 | PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11"]
|
20 | 22 |
|
21 | 23 |
|
@@ -61,6 +63,7 @@ def get_mypy_analysed_type(fname):
|
61 | 63 | )
|
62 | 64 | .replace("numpy._typing.", "")
|
63 | 65 | .replace("numpy.", "")
|
| 66 | + .replace("tuple", "Tuple") |
64 | 67 | )
|
65 | 68 |
|
66 | 69 |
|
@@ -127,133 +130,36 @@ def convert_lines():
|
127 | 130 | "tuples(text(), text(), text(), text(), text(), text())",
|
128 | 131 | "tuple[Any, ...]",
|
129 | 132 | ),
|
130 |
| - ( |
131 |
| - 'arrays(dtype=np.dtype("int32"), shape=1)', |
132 |
| - "ndarray[Any, dtype[signedinteger[_32Bit]]]", |
133 |
| - ), |
134 |
| - ( |
135 |
| - "arrays(dtype=np.dtype(int), shape=1)", |
136 |
| - "ndarray[Any, dtype[signedinteger[Any]]]", |
137 |
| - ), |
138 |
| - ( |
139 |
| - "boolean_dtypes()", |
140 |
| - "dtype[bool_]", |
141 |
| - ), |
142 |
| - ( |
143 |
| - "unsigned_integer_dtypes(sizes=8)", |
144 |
| - "dtype[unsignedinteger[_8Bit]]", |
145 |
| - ), |
146 |
| - ( |
147 |
| - "unsigned_integer_dtypes(sizes=16)", |
148 |
| - "dtype[unsignedinteger[_16Bit]]", |
149 |
| - ), |
150 |
| - ( |
151 |
| - "unsigned_integer_dtypes(sizes=32)", |
152 |
| - "dtype[unsignedinteger[_32Bit]]", |
153 |
| - ), |
154 |
| - ( |
155 |
| - "unsigned_integer_dtypes(sizes=64)", |
156 |
| - "dtype[unsignedinteger[_64Bit]]", |
157 |
| - ), |
158 |
| - ( |
159 |
| - "unsigned_integer_dtypes()", |
160 |
| - "dtype[unsignedinteger[Any]]", |
161 |
| - ), |
162 |
| - ( |
163 |
| - "unsigned_integer_dtypes(sizes=(8, 16))", |
164 |
| - "dtype[unsignedinteger[Any]]", |
165 |
| - ), |
166 |
| - ( |
167 |
| - "integer_dtypes(sizes=8)", |
168 |
| - "dtype[signedinteger[_8Bit]]", |
169 |
| - ), |
170 |
| - ( |
171 |
| - "integer_dtypes(sizes=16)", |
172 |
| - "dtype[signedinteger[_16Bit]]", |
173 |
| - ), |
174 |
| - ( |
175 |
| - "integer_dtypes(sizes=32)", |
176 |
| - "dtype[signedinteger[_32Bit]]", |
177 |
| - ), |
178 |
| - ( |
179 |
| - "integer_dtypes(sizes=64)", |
180 |
| - "dtype[signedinteger[_64Bit]]", |
181 |
| - ), |
182 |
| - ( |
183 |
| - "integer_dtypes()", |
184 |
| - "dtype[signedinteger[Any]]", |
185 |
| - ), |
186 |
| - ( |
187 |
| - "integer_dtypes(sizes=(8, 16))", |
188 |
| - "dtype[signedinteger[Any]]", |
189 |
| - ), |
190 |
| - ( |
191 |
| - "floating_dtypes(sizes=16)", |
192 |
| - "dtype[floating[_16Bit]]", |
193 |
| - ), |
194 |
| - ( |
195 |
| - "floating_dtypes(sizes=32)", |
196 |
| - "dtype[floating[_32Bit]]", |
197 |
| - ), |
198 |
| - ( |
199 |
| - "floating_dtypes(sizes=64)", |
200 |
| - "dtype[floating[_64Bit]]", |
201 |
| - ), |
202 |
| - ( |
203 |
| - "floating_dtypes(sizes=128)", |
204 |
| - "dtype[floating[_128Bit]]", |
205 |
| - ), |
206 |
| - ( |
207 |
| - "floating_dtypes()", |
208 |
| - "dtype[floating[Any]]", |
209 |
| - ), |
210 |
| - ( |
211 |
| - "floating_dtypes(sizes=(16, 32))", |
212 |
| - "dtype[floating[Any]]", |
213 |
| - ), |
214 |
| - ( |
215 |
| - "complex_number_dtypes(sizes=64)", |
216 |
| - "dtype[complexfloating[_32Bit, _32Bit]]", |
217 |
| - ), |
218 |
| - ( |
219 |
| - "complex_number_dtypes(sizes=128)", |
220 |
| - "dtype[complexfloating[_64Bit, _64Bit]]", |
221 |
| - ), |
222 |
| - ( |
223 |
| - "complex_number_dtypes(sizes=256)", |
224 |
| - "dtype[complexfloating[_128Bit, _128Bit]]", |
225 |
| - ), |
226 |
| - ( |
227 |
| - "complex_number_dtypes()", |
228 |
| - "dtype[complexfloating[Any, Any]]", |
229 |
| - ), |
230 |
| - ( |
231 |
| - "complex_number_dtypes(sizes=(64, 128))", |
232 |
| - "dtype[complexfloating[Any, Any]]", |
233 |
| - ), |
234 |
| - ( |
235 |
| - "integer_array_indices(shape=(2, 3))", |
236 |
| - "tuple[ndarray[Any, dtype[signedinteger[Any]]], ...]", |
237 |
| - ), |
238 |
| - ( |
239 |
| - 'integer_array_indices(shape=(2, 3), dtype=np.dtype("int32"))', |
240 |
| - "tuple[ndarray[Any, dtype[signedinteger[_32Bit]]], ...]", |
241 |
| - ), |
242 |
| - ( |
243 |
| - 'integer_array_indices(shape=(2, 3), dtype=np.dtype("uint8"))', |
244 |
| - "tuple[ndarray[Any, dtype[unsignedinteger[_8Bit]]], ...]", |
245 |
| - ), |
246 | 133 | # Note: keep this in sync with the equivalent test for Pyright
|
247 | 134 | ],
|
248 | 135 | )
|
249 | 136 | def test_revealed_types(tmp_path, val, expect):
|
250 | 137 | """Check that Mypy picks up the expected `X` in SearchStrategy[`X`]."""
|
251 | 138 | f = tmp_path / "check.py"
|
252 | 139 | f.write_text(
|
253 |
| - "import numpy as np\n" |
254 |
| - "from hypothesis.extra.numpy import *\n" |
255 |
| - "from hypothesis.strategies import *\n" |
256 |
| - f"reveal_type({val})\n", |
| 140 | + textwrap.dedent( |
| 141 | + f""" |
| 142 | + from hypothesis.strategies import * |
| 143 | + reveal_type({val}) |
| 144 | + """ |
| 145 | + ), |
| 146 | + encoding="utf-8", |
| 147 | + ) |
| 148 | + typ = get_mypy_analysed_type(f) |
| 149 | + assert typ == f"SearchStrategy[{expect}]" |
| 150 | + |
| 151 | + |
| 152 | +@pytest.mark.parametrize("val,expect", NUMPY_REVEALED_TYPES) |
| 153 | +def test_numpy_revealed_types(tmp_path, val, expect): |
| 154 | + f = tmp_path / "check.py" |
| 155 | + f.write_text( |
| 156 | + textwrap.dedent( |
| 157 | + f""" |
| 158 | + import numpy as np |
| 159 | + "from hypothesis.extra.numpy import * |
| 160 | + reveal_type({val}) |
| 161 | + """ |
| 162 | + ), |
257 | 163 | encoding="utf-8",
|
258 | 164 | )
|
259 | 165 | typ = get_mypy_analysed_type(f)
|
|
0 commit comments