|
33 | 33 | from dataclasses import KW_ONLY, dataclass |
34 | 34 | from functools import partial |
35 | 35 | from pathlib import Path |
36 | | -from typing import NewType, NoReturn, assert_never |
| 36 | +from typing import Final, NewType, NoReturn, assert_never |
37 | 37 |
|
38 | 38 | from pysource_codegen import generate as generate_random_code |
39 | 39 | from pysource_minimize import CouldNotMinimize, minimize as minimize_repro |
|
44 | 44 | Seed = NewType("Seed", int) |
45 | 45 | ExitCode = NewType("ExitCode", int) |
46 | 46 |
|
| 47 | +TY_TARGET_PLATFORM: Final = "linux" |
| 48 | + |
| 49 | +# ty supports `--python-version=3.8`, but typeshed only supports 3.9+, |
| 50 | +# so that's probably the oldest version we can usefully test with. |
| 51 | +OLDEST_SUPPORTED_PYTHON: Final = "3.9" |
| 52 | + |
47 | 53 |
|
48 | 54 | def ty_contains_bug(code: str, *, ty_executable: Path) -> bool: |
49 | 55 | """Return `True` if the code triggers a panic in type-checking code.""" |
50 | 56 | with tempfile.TemporaryDirectory() as tempdir: |
51 | 57 | input_file = Path(tempdir, "input.py") |
52 | 58 | input_file.write_text(code) |
53 | 59 | completed_process = subprocess.run( |
54 | | - [ty_executable, "check", input_file], capture_output=True, text=True |
| 60 | + [ |
| 61 | + ty_executable, |
| 62 | + "check", |
| 63 | + input_file, |
| 64 | + "--python-version", |
| 65 | + OLDEST_SUPPORTED_PYTHON, |
| 66 | + "--python-platform", |
| 67 | + TY_TARGET_PLATFORM, |
| 68 | + ], |
| 69 | + capture_output=True, |
| 70 | + text=True, |
55 | 71 | ) |
56 | 72 | return completed_process.returncode not in {0, 1, 2} |
57 | 73 |
|
@@ -137,7 +153,10 @@ def print_description(self, index: int, num_seeds: int) -> None: |
137 | 153 | case Executable.RUFF: |
138 | 154 | panic_message = f"The following code triggers a {new}parser bug:" |
139 | 155 | case Executable.TY: |
140 | | - panic_message = f"The following code triggers a {new}ty panic:" |
| 156 | + panic_message = ( |
| 157 | + f"The following code triggers a {new}ty panic with " |
| 158 | + f"`--python-version={OLDEST_SUPPORTED_PYTHON} --python-platform={TY_TARGET_PLATFORM}`:" |
| 159 | + ) |
141 | 160 | case _ as unreachable: |
142 | 161 | assert_never(unreachable) |
143 | 162 |
|
|
0 commit comments