From 449fa5c6529870da820c2f0cdc2917e40e0e1438 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 1 Sep 2026 10:57:45 -0400 Subject: [PATCH] fix: remove outdated ninja_syntax stub The stub did not match the shipped ninja_syntax.py: it typed `output` as `str`, `build()` outputs as `list[str]` only, and gave `build()` no return type. Upstream annotates ninja_syntax.py, and the package has py.typed, so type checkers can use the real annotations and cannot drift again. Closes #344 Assisted-by: ClaudeCode:claude-opus-5 --- pyproject.toml | 5 +++++ src/ninja/ninja_syntax.pyi | 37 ------------------------------------- tests/test_ninja.py | 9 +++++++++ 3 files changed, 14 insertions(+), 37 deletions(-) delete mode 100644 src/ninja/ninja_syntax.pyi diff --git a/pyproject.toml b/pyproject.toml index 03ab44b..9fb0be6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -159,6 +159,11 @@ strict = true enable_error_code = ["ignore-without-code", "truthy-bool", "redundant-expr"] warn_unreachable = true +# ninja_syntax.py is added by the build from the ninja sources; it is annotated upstream +[[tool.mypy.overrides]] +module = "ninja.ninja_syntax" +ignore_missing_imports = true + [tool.ruff] src = ["src"] diff --git a/src/ninja/ninja_syntax.pyi b/src/ninja/ninja_syntax.pyi deleted file mode 100644 index 252beff..0000000 --- a/src/ninja/ninja_syntax.pyi +++ /dev/null @@ -1,37 +0,0 @@ -from collections.abc import Mapping, Sequence -from os import PathLike - -def escape_path(word: str) -> str: ... - -class Writer: - output: str - width: int - - def __init__(self, output: str, width: int = ...): ... - def newline(self) -> None: ... - def comment(self, text: str) -> None: ... - def variable(self, key: str, value: list[str] | str, indent: int = ...) -> None: ... - def pool(self, name: str, depth: int) -> None: ... - def rule(self, name: str, command: str, description: str | None = None, - depfile: str | None = None, generator: bool = False, - pool: str | None = None, restat: bool = False, - rspfile: str | None = None, rspfile_content: str | None = None, - deps: str | None = None) -> None: - ... - - def build(self, outputs: list[str], rule: str, inputs: list[str] | None = None, - implicit: list[str] | None = None, order_only: list[str] | None = None, - variables: dict[str, str] | None = None, - implicit_outputs: list[str] | None = None, - pool: str | None = None, dyndep: str | None = None) -> None: - ... - def include(self, path: str | PathLike[str]) -> None: ... - def subninja(self, path: str | PathLike[str]) -> None: ... - def default(self, paths: Sequence[str | PathLike[str]]) -> None: ... - def close(self) -> None: ... - -def as_list(input: list[str] | str | None) -> list[str]: ... - -def escape(string: str) -> str: ... - -def expand(string: str, vars: Mapping[str, str], local_vars: Mapping[str, str]=...) -> str: ... diff --git a/tests/test_ninja.py b/tests/test_ninja.py index 3277b7e..23fae44 100644 --- a/tests/test_ninja.py +++ b/tests/test_ninja.py @@ -1,6 +1,8 @@ from __future__ import annotations +import inspect import os +import pathlib import subprocess import sys import sysconfig @@ -9,6 +11,7 @@ from importlib_metadata import distribution import ninja +from ninja import ninja_syntax from . import push_argv @@ -48,3 +51,9 @@ def test_ninja_script(): assert scripts[0].stem == "ninja" output = subprocess.check_output([str(scripts[0]), "--version"]).decode("ascii") assert output.splitlines()[0] == expected_version + + +def test_ninja_syntax_typed(): + """Type checkers must use the annotations in ninja_syntax.py, not an outdated stub.""" + assert not pathlib.Path(ninja_syntax.__file__).with_suffix(".pyi").exists() + assert inspect.signature(ninja_syntax.Writer.build).return_annotation != inspect.Signature.empty