Skip to content

Exclude missing type variable defaults from precision reports - #22429

Closed
mengqing88 wants to merge 2 commits into
python:masterfrom
mengqing88:fix/report-missing-typevar-defaults
Closed

mengqing88 wants to merge 2 commits into
python:masterfrom
mengqing88:fix/report-missing-typevar-defaults

Conversation

@mengqing88

@mengqing88 mengqing88 commented Nov 10, 2026 •

Copy link
Copy Markdown

Precision reports classify fully annotated generic functions as imprecise because a type variable without a default stores AnyType(TypeOfAny.from_omitted_generics) as its internal default. For example, a signature-preserving Callable[P, T] decorator reports imprecision on P.args / P.kwargs even though no Any is present in the source and the wrapped return type is preserved. The same sentinel also inflates types-of-anys.txt: the new generic-only fixture currently reports 24 omitted-generic Anys.

Exclude the missing-default sentinel when traversing TypeVar, ParamSpec, and TypeVarTuple for statistics. Apply the same traversal to precision classification and Any collection so their results remain consistent. Actual defaults, upper bounds, constraints, and ParamSpec prefixes are still traversed, and real omitted generic arguments are still reported. The change is confined to statistics; it does not change type checking, inference, or the treatment of calls accepting Any.

Validation on Python 3.11 / Windows:

  • The four new data-driven cases produce three failures and one passing control on unmodified master, and all pass with the fix.
  • All report cases plus the Cobertura unit tests: 46 passed (python -m pytest -n0 -q mypy/test/testcheck.py mypy/test/testcmdline.py mypy/test/testreports.py -k 'reports.test or CoberturaReportSuite').
  • Self-check: 196 source files passed (python -m mypy --config-file mypy_self_check.ini -p mypy).
  • Black, Ruff, and git diff --check passed.
  • Independent Cobertura probes confirm that the ParamSpec example has no remaining imprecise lines while a typed call to json.dumps retains its existing Any marker.

Python 3.10 CI follow-up: the generic-only report fixture now imports TypeVarTuple and Unpack from typing_extensions. The original failure was reproduced on Python 3.10 before this change; all 23 command-line report cases pass on both Python 3.10 and Python 3.11 after it.

AI assistance: Codex assisted with the investigation, implementation, and test preparation.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pywin32 (https://github.com/mhammond/pywin32)
  ./pythonwin/pywin/test/_dbgscript.py: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
- version: 2.5.0+dev.b83696ea8099ef3772a5a2bc2c49f2b05340c37a
+ version: 2.5.0+dev.a57c949e0039fc6d08c8ef5cf3cce61e1f77a361

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants