From 9e3fbc1f25a0037a155583ed0ab67972a084f661 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:59:40 +0000 Subject: [PATCH 1/2] Initial plan From fd748335fedbe99c2a40e96dbcd0286888a642a9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 16 Oct 2026 16:02:33 +0000 Subject: [PATCH 2/2] Filter PEP 798 scan paths Co-authored-by: cclauss <3709715+cclauss@users.noreply.github.com> --- scripts/find_and_fix_pep798.py | 22 ++++++++++++++++++---- tests/test_find_and_fix_pep798.py | 19 +++++++++++++++++-- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/scripts/find_and_fix_pep798.py b/scripts/find_and_fix_pep798.py index 594d1deb8498..016a095b653a 100755 --- a/scripts/find_and_fix_pep798.py +++ b/scripts/find_and_fix_pep798.py @@ -24,7 +24,9 @@ The rewritten source uses Python 3.15+ syntax, so fixed files need 3.15+. Usage: - scripts/find_and_fix_pep798.py [--fix] PATH [PATH ...] + scripts/find_and_fix_pep798.py [--fix] [PATH ...] + +If no path is provided, the current working directory is searched. Without ``--fix`` the script only reports and exits with status 1 if any opportunities were found. @@ -213,14 +215,26 @@ def fix_source(source: str) -> str: def iter_python_files(paths: Iterable[Path]) -> Iterator[Path]: for path in paths: if path.is_dir(): - yield from sorted(path.rglob("*.py")) - else: + yield from sorted( + candidate + for candidate in path.rglob("*.py") + if not any(part.startswith(".") for part in candidate.parent.parts) + ) + elif path.suffix == ".py" and not any( + part.startswith(".") for part in path.parent.parts + ): yield path def main(argv: list[str] | None = None) -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) - parser.add_argument("paths", nargs="+", type=Path, help="files or directories") + parser.add_argument( + "paths", + nargs="*", + type=Path, + default=[Path.cwd()], + help="Python files or directories (defaults to the current directory)", + ) parser.add_argument("--fix", action="store_true", help="rewrite files in place") args = parser.parse_args(argv) diff --git a/tests/test_find_and_fix_pep798.py b/tests/test_find_and_fix_pep798.py index c74496347e58..0817921b33f6 100644 --- a/tests/test_find_and_fix_pep798.py +++ b/tests/test_find_and_fix_pep798.py @@ -97,13 +97,16 @@ def test_multiline_comprehension() -> None: def test_iter_python_files(tmp_path: Path) -> None: (tmp_path / "sub").mkdir() + (tmp_path / ".hidden").mkdir() first = tmp_path / "a.py" second = tmp_path / "sub" / "b.py" other = tmp_path / "c.txt" - for path in (first, second, other): + hidden = tmp_path / ".hidden" / "hidden.py" + for path in (first, second, other, hidden): path.write_text("") assert list(iter_python_files([tmp_path])) == [first, second] - assert list(iter_python_files([other])) == [other] + assert list(iter_python_files([other])) == [] + assert list(iter_python_files([hidden])) == [] def test_main_reports_without_fixing( @@ -137,6 +140,18 @@ def test_main_clean_file_returns_zero( assert "0 PEP 798 opportunities found" in capsys.readouterr().out +def test_main_defaults_to_current_directory( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str] +) -> None: + path = tmp_path / "mod.py" + path.write_text("a = [y for x in xs for y in x]\n") + monkeypatch.chdir(tmp_path) + assert main([]) == 1 + output = capsys.readouterr().out + assert f"{path}:1:" in output + assert "1 PEP 798 opportunity found" in output + + def test_main_skips_syntax_errors( tmp_path: Path, capsys: pytest.CaptureFixture[str] ) -> None: