typeddjango / pytest-mypy-plugins

pytest plugin for testing mypy types, stubs, and plugins
https://pypi.org/project/pytest-mypy-plugins/
MIT License
100 stars 26 forks source link

How to solve Python 3.8/3.9 changes in typing representation #126

Closed stdedos closed 1 year ago

stdedos commented 1 year ago

I am facing some smaller

https://github.com/stdedos/matplotlib-stubs-hoel/actions/runs/6082319105/job/16499842737#step:6:107

E     E: ...], bytes: bool = ...) -> Tuple[float, float, float, float]
E     A: ...], bytes: bool = ...) -> tuple[float, float, float, float]

or bigger problems

https://github.com/stdedos/matplotlib-stubs-hoel/actions/runs/6082319105/job/16499843642#step:6:107

E     E: ...f __call__(self, X: Union[int, float], alpha: Optional[float], bytes:...
E     A: ...f __call__(self, X: int | float, alpha: float | None, bytes: bool = ....

when trying to tox-equivalent test with pytest-mypy-plugins.

Idk; would you be open to exposing e.g. sys.version_info?

Something like

from jinja2 import Environment, FileSystemLoader
import sys

env = Environment(loader=FileSystemLoader('.'))
env.globals['sys'] = {'version_info': sys.version_info}

template = env.get_template('your_template.jinja')

# In your_template.jinja
{% if sys.version_info[0] == 3 %}
  Python 3.x is being used.
{% else %}
  Not using Python 3.x.
{% endif %}

Or, to avoid the X | Y problem:

How can I just No overload variant of "__call__" of "Colormap" matches argument type "{{ rt }}" [call-overload] is asserted, and ignore the notes?

sobolevn commented 1 year ago

Try:

force_uppercase_builtins = true
force_union_syntax = true
stdedos commented 1 year ago

Nice finding! ... but it doesn't seem to be included here 😕 https://mypy.readthedocs.io/en/stable/config_file.html

(Also, how about force_lowercase_builtins and force_pipe_syntax? 😝 )

sobolevn commented 1 year ago

@stdedos please, open a mypy issue about that! I will include them right away!

stdedos commented 1 year ago

@stdedos please, open a mypy issue about that! I will include them right away!

You ... did that already? 😅 https://github.com/python/mypy/pull/16048

Or did you mean a PR for you here? 😕