Cannot suppress python_version-related errors in third-party code
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
If i have python_version = 3.5 set, it's not possible to tell mypy to ignore related syntax errors it finds in dependencies.
Use case: i have code which needs to support python 3.5, as well as newer versions. I run mypy against it under various versions of python, with python_version = 3.5 set so that i don't accidentally introduce something which is incompatible (like variable annotations) which might not get caught until later. This has worked fine until some of the dependencies have started using variable annotations.
To Reproduce
- Create a venv using python 3.6+.
pip install mypy importlib-metadata# Using importlib-metadata as an example lib which uses variable annotations- Create
setup.cfgwith:
[mypy]
python_version = 3.5
[mypy-importlib_metadata]
ignore_errors = True
- Create
test.pywith:
import importlib_metadata
- Run
mypy test.py
Expected Behavior
mypy should enforce python_version = 3.5 for test.py, but it should ignore any version-related issues in importlib_metadata.
Actual Behavior
mypy fails with:
venv/lib/python3.8/site-packages/importlib_metadata/__init__.py:88: error: Variable annotation syntax is only supported in Python 3.6 and greater
Found 1 error in 1 file (errors prevented further checking)
mypy doesn't seem to treat this as a 'fatal' error, either, as setting pdb = True has no effect.
Your Environment
- mypy 0.790 and 0.800
- python 3.6.7, 3.6.12 and 3.8.5
- Debian Stretch and Linux Mint 20.1 (Equivalent to Ubuntu 20.04)
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 setup.cfg configuration with python_version = 3.5, the importlib_metadata dependency, test.py, and mypy test.py. Trace how mypy handles version-related syntax errors from imported dependencies; done means test.py still enforces Python 3.5 while the dependency's version-related errors are suppressed by ignore_errors.
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
- Clearly specified
- Newbie friendliness
- 35/100