Add a way for mypy coverage reports to omit certain lines or functions from precision checking
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
When looking at a coverage report which shows the precision of the types on my code, I very frequently find that the same handful of functions are responsible for lines being marked "imprecise".
In general:
- library or stdlib functions which really consume
Any, likeLogger.debug - library or stdlib functions which produce
Any, likesqlalchemy.orm.query.Query.scalar - functions in my own code where the type is
Anyto avoid other issues (e.g. absence of unsafe unions)
I would like to be able to tell mypy to exempt certain usages from its reporting.
Several tools support this via comments (# pragma: no cover, # fmt: off, # noqa), but coverage has another interface which may be better suited to mypy: you can specify expressions which are skipped. (tool.coverage.report.exclude_lines in pyproject.toml).
Being able to stipulate something like:
mypy-coverage-precision-exclude =
logging.Logger.debug
logging.Logger.error
sqlalchemy.orm.query.Query.scalar
mymodule.myfunc
would make the coverage reporting much more useful, because it would eliminate "false negatives" on lines that really ought to have imprecise types.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files or tests. Start by locating mypy’s coverage-precision reporting and configuration parsing, then trace how reported usages are identified. Done means users can configure exclusions for specified functions or usages and the coverage report omits those entries without affecting normal type checking.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100