mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Support multiple Python versions in config's python_version

Open jamesbraza opened this issue 4 years ago • 1 comments

Feature

The repo I work within support Python 3.7 - 3.9 right now. I use mypy to check the repo's typing.

Currently, in my pyproject.toml config, I have python_version = 3.7.

I would like to allow something like Tox's envlist, which allows one to call out multiple Python versions to check.

I don't care about checking bugfix versions of Python, only minor versions (e.g. 3.7, 3.8, 3.9).

Workaround

A workaround is to invoke mypy multiple times, passing the Python version as a command line arg on each invocation:

mypy --python-version 3.7 -p foo
mypy --python-version 3.8 -p foo
mypy --python-version 3.9 -p foo

Pitch

This would be a convenience feature for developers using mypy in repos that support multiple versions of Python.

I imagine the config looking something like this:

# For backwards compatibility
python_version = 3.7

# Proposing adding this as an alternate option
python_version = [3.7, 3.8, 3.9]

I am not familiar with mypy's internals, I imagine this could be a difficult feature to add. Just thought I would throw in my two cents.

jamesbraza avatar Jun 30 '21 17:06 jamesbraza

This would be very useful in CI pipelines while spinning up matrices of tests against multiple Python versions. aka, having the benefit of using one config file vs. specifying the version to check against in every job.

emmeowzing avatar Sep 10 '22 18:09 emmeowzing

Closing as a duplicate of https://github.com/python/mypy/issues/12286 , since that has more discussion

hauntsaninja avatar Aug 13 '23 22:08 hauntsaninja