Errors in followed imports cause crash without a way to ignore unless import following is entirely disabled
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
I think related to https://github.com/python/mypy/issues/6897 which was closed, but I often want to enable type checking on a module that imports a number of 3p packages that I have no control over.
However, I am finding that the import-following behavior for mypy is quite sensitive to things that I can't really control or easily ignore. I would expect that --follow-imports=silent would gracefully degrade in situations where this happens, but I find many cases where a stray comment (e.g. # type: some comment that's not actually a type specification) will cause a syntax error that causes the whole execution to error, and I can't find a way to ignore it without completely disabling --follow-imports.
I've encountered this with stray comments in tensorflow, for example. Is there any way to more gracefully fallback and recover from these kinds of errors in mypy? Or at least allow more fine-grained control on import following to not fail on syntax errors for specific external modules?
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
Start by reproducing the failure with mypy's --follow-imports=silent option and an imported third-party module containing a stray type-like comment, such as the reported TensorFlow case. Trace how syntax errors in followed imports are handled; done means external import errors are recoverable or can be ignored with finer-grained control without disabling import following entirely.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100