[FEAT] add PEP 561 py.typed marker so type checkers honour inline annotations - #1149
[FEAT] add PEP 561 py.typed marker so type checkers honour inline annotations#1149jbbqqf wants to merge 2 commits into
py.typed marker so type checkers honour inline annotations#1149Conversation
…nnotations PEP 561 requires a `py.typed` marker file at the package root for type checkers (pyright/mypy/pylance) to pick up the inline type annotations a package ships. Without it, pylance emits "Stub file not found for 'statsforecast'" and skips type checking. The package already has type annotations across `python/statsforecast`, so the marker is the only missing piece. `MANIFEST.in` already covers the file via `recursive-include python/statsforecast *`, and `pyproject.toml`'s `[tool.setuptools.package-data] "*" = ["**/*"]` forwards it into the wheel — both verified by importing the editable install and locating the file next to `statsforecast.__file__`. Fixes Nixtla#1121.
|
|
|
Hey @jbbqqf thanks for your contribution! Can you please sign the license? |
|
Thanks for your contribution, @jbbqqf. We're preparing a new StatsForecast release and need to move quickly on this fix. Since the license agreement hasn't been signed yet, we'll merge #1176 instead, which addresses the same issue. It was opened after yours, but it keeps the change minimal (there's really no need for a test). We encourage you to sign the license agreement in your other PR #1148, as that's something we would like to merge. |
Summary
Add an empty
python/statsforecast/py.typedmarker so PEP 561-aware type checkers (pyright/pylance/mypy) honour the inline annotations already present in the codebase.Fixes #1121 — feat: Consider adding
py.typedfile marker for type-checking supportContext
PEP 561 (spec) defines two mechanisms for shipping type information:
py.typedmarker file at the package root.statsforecastalready has inline annotations acrosspython/statsforecast/*.py, but the marker is missing. Without it, pyright/pylance treat the package as untyped — the user reported pylance emittingStub file not found for "statsforecast"whenever the package is imported.The marker has to ride along into the built wheel. Two pieces are already in place:
MANIFEST.inincludesrecursive-include python/statsforecast *, which picks uppy.typedfor the sdist.pyproject.toml's[tool.setuptools.package-data] "*" = ["**/*"]forwards every file under the package directory into the wheel.So adding the marker file is sufficient — no other build configuration change is needed. The new regression test imports
statsforecastand asserts the marker is co-located withstatsforecast.__file__(i.e. the file made it through the install path).Changes
python/statsforecast/py.typed— new empty file (PEP 561 marker).tests/test_utils.py— newtest_py_typed_marker_is_packagedregression. It mirrors the path a real consumer would inspect: import the package, then assertpy.typedsits next tostatsforecast.__file__.Reproduce BEFORE/AFTER yourself (copy-paste)
For an end-to-end pyright check (the user's actual scenario):
On origin/main, pyright reports
error: Stub file not found for "statsforecast". On this branch it reports zero diagnostics for the import line.What I ran locally
pytest tests/test_utils.py -v --no-cov→ 2/2 passed (was 1; the newtest_py_typed_marker_is_packagedfails on origin/main and passes here).Edge cases tested
pip install -e .py.typedsits next tostatsforecast.__file__test_py_typed_marker_is_packagedrecursive-include python/statsforecast *already covers itpy.typedships in source tarballpython -m build --sdistinspection (no test added — covered by MANIFEST.in convention)[tool.setuptools.package-data] "*" = ["**/*"]already forwards itpy.typedships in the wheelRisk / blast radius
Pure addition. Type checkers that previously ignored
statsforecastwill now read its annotations; that may surface new diagnostics in downstream projects, but the annotations are already present in the source and have already been informally guiding hover-docs and IDE completions. No runtime behaviour change.Release note
PR drafted with assistance from Claude Code. The change matches the standard PEP 561 recipe and the existing MANIFEST.in / package-data configuration carries the marker into both sdist and wheel without further changes.