build: add ty type checking alongside mypy - #1505
Draft
s3alfisc wants to merge 6 commits into
Draft
Conversation
ty resolves imports from the environment it runs in, so it ships with the runtime dependencies rather than with the lint environment. conda-forge's ty requires CPython >= 3.11, which rules out the shared default dependency table and the py310 environment. The exclude list keeps ty away from the files the open estimation-state stack rewrites; the mypy-to-ty migration layer that lands on top of that stack removes them. mypy still owns the `# type: ignore` comments, so ty must not report them as unused.
`StructuredFormula` serves `lhs`, `rhs` and `root` from `Structured.__getattr__`, so a type checker sees none of them on the `Formula` base class the parser returns. Two accessors in the compat module carry that knowledge, and the parser's properties now declare the `SimpleFormula` they actually return instead of the abstract base, which is neither sized nor iterable. `is_structured_formula` is gone: `exogenous` needs the narrowing that only a direct `isinstance` provides, and two spellings of the same check are worse than one.
`panelview` returns the Axes its docstring already promises, `lpdid` and `LPDID` accept the optional `xfml` their runtime checks and base class allow, and `_coefplot_matplotlib` reads the "jet" colormap through the registry rather than the dynamically populated `pyplot.cm` namespace. Rebinding the saturated event-study methods onto a plain `Feols` keeps a targeted suppression: replacing `Feols.iplot`, a `functools.partial` attribute, needs a result class of its own rather than an annotation change.
The separation loop fits exactly one model, the CRV path needs a pandas frame rather than any narwhals-native one, the torch demeaner's inner implementation handles the `None` factor list its wrapper passes, and the Gelbach decomposition indexes and multiplies compressed sparse matrices, which scipy's `spmatrix` matrix-semantics mixin does not provide. The remaining suppressions name a third-party gap each: numba's `prange` marker class, and rpy2, which ships only with the `r` pixi feature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds ty 0.0.78 as a blocking CI type check alongside the existing mypy pre-commit hook, as the first step of #1104. ty lives in a
typecheckpixi feature on the py311 to py314 environments (conda-forge's ty needs CPython 3.11+), with atype-checktask and a[tool.ty]configuration; CI runspixi run -e py312 type-check.Of 169 diagnostics on master, 60 are fixed for real (formulaic formula sides read through typed accessors, honest annotations in the DiD, decomposition, and plotting entries, real narrowing fixes) and 11 unused-ignore warnings are silenced because mypy still owns those comments. The files rewritten by the open estimation-state stack (#1499 to #1501) are excluded temporarily and will be un-excluded, together with removing mypy, in a follow-up layer on top of that stack. Every remaining suppression is a
# ty: ignore[rule]with a reason naming the third-party gap. No runtime behavior changes.Verification
Passed locally at the head:
ty checkclean, mypy, ruff, release contract 1355/1355, targeted formula, DiD, decomposition, and plotting suites, broad Python-only suite (pre-existingtorch_mpsfailures excluded), fast live-R 22/22.pixi.lockadds only ty. Deferred to CI: thetype-checkjob itself, R suites, docs.