python / python/mypy

Cannot suppress python_version-related errors in third-party code

Open
#9,972 12 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

  1. Create a venv using python 3.6+.
  2. pip install mypy importlib-metadata # Using importlib-metadata as an example lib which uses variable annotations
  3. Create setup.cfg with:
[mypy]
python_version = 3.5

[mypy-importlib_metadata]
ignore_errors = True
  1. Create test.py with:
import importlib_metadata
  1. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.