Skip to content

Commit 7519f6c

Browse files
authored
Print Python version and Python platform in the fuzzer output when fuzzing fails (astral-sh#21844)
1 parent 4686111 commit 7519f6c

3 files changed

Lines changed: 50 additions & 4 deletions

File tree

python/py-fuzzer/fuzz.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from dataclasses import KW_ONLY, dataclass
3434
from functools import partial
3535
from pathlib import Path
36-
from typing import NewType, NoReturn, assert_never
36+
from typing import Final, NewType, NoReturn, assert_never
3737

3838
from pysource_codegen import generate as generate_random_code
3939
from pysource_minimize import CouldNotMinimize, minimize as minimize_repro
@@ -44,14 +44,30 @@
4444
Seed = NewType("Seed", int)
4545
ExitCode = NewType("ExitCode", int)
4646

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+
4753

4854
def ty_contains_bug(code: str, *, ty_executable: Path) -> bool:
4955
"""Return `True` if the code triggers a panic in type-checking code."""
5056
with tempfile.TemporaryDirectory() as tempdir:
5157
input_file = Path(tempdir, "input.py")
5258
input_file.write_text(code)
5359
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,
5571
)
5672
return completed_process.returncode not in {0, 1, 2}
5773

@@ -137,7 +153,10 @@ def print_description(self, index: int, num_seeds: int) -> None:
137153
case Executable.RUFF:
138154
panic_message = f"The following code triggers a {new}parser bug:"
139155
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+
)
141160
case _ as unreachable:
142161
assert_never(unreachable)
143162

python/py-fuzzer/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ requires = ["hatchling"]
1919
build-backend = "hatchling.build"
2020

2121
[dependency-groups]
22-
dev = ["mypy", "ruff"]
22+
dev = ["mypy", "ruff", "ty"]
2323

2424
[tool.hatch.build.targets.wheel]
2525
include = ["fuzz.py"]

python/py-fuzzer/uv.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)