You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Missing file pyplot.pyi for mypy typing #26919
Pyplot is typed inline, so the lack of pyi is intentional.
show, along with draw_if_interactive and new_figure_manager, are complicated from a static typing perspective because their signatures are actually dynamically set at runtime, and can change when switching backends...
We could maybe at least add a -> None/-> FigureManagerBase to them which would elide this warning, though -> None will cause us to have to add ignores because we return calls to the figure manager show/draw_if_interactive
backend_bases does define what the expected signature of these methods is, so arguably we could implement them with those expected signatures, but if any backend out there is adding args/kwargs to these methods, it might break them.
Note that no-untyped-call is not in the default mypy configuration, so to reproduce you must also pass --disallow-untyped-calls (or --strict or have that enabled in a config file)
Expected Outcome
I expect that no error should be reported by mypy when calling plt.show() as it has not produced errors in previous versions of matplotlib.
Steps Taken:
I have tried updating both mypy and matplotlib to their latest versions using pip install --upgrade mypy matplotlib. The issue still persists.
I guess I'd be okay with that... I'm personally don't like no-untyped-call as an error to flag, and if it weren't for such, would probably prefer to just leave things like this untyped... (I think untyped is preferable to Any just being sprinkled about, in general)
But the pragmatic answer is probably to add something so that it doesn't flag for users.
I'm 50/50 on whether to go with None or Any, as I think backends should not have a return for the pyplot_show function (based on other type hints/docstrings), but if it does return, we will return whatever it gives us... (actually I tried it and mypy doesn't complain about the return when we say the return type is None)
I will note that Any as a return is also flagged by --strict, though not in calling code, only if we did that when running against mpl itself, which we are still quite far from being able to do properly.
Activity
ksunden commentedon Sep 26, 2023
Pyplot is typed inline, so the lack of
pyiis intentional.show, along withdraw_if_interactiveandnew_figure_manager, are complicated from a static typing perspective because their signatures are actually dynamically set at runtime, and can change when switching backends...We could maybe at least add a
-> None/-> FigureManagerBaseto them which would elide this warning, though-> Nonewill cause us to have to add ignores because wereturncalls to the figure managershow/draw_if_interactivebackend_bases does define what the expected signature of these methods is, so arguably we could implement them with those expected signatures, but if any backend out there is adding args/kwargs to these methods, it might break them.
Note that
no-untyped-callis not in the default mypy configuration, so to reproduce you must also pass--disallow-untyped-calls(or--strictor have that enabled in a config file)Mihirshrivas commentedon Sep 26, 2023
Issue Description
I have encountered an issue when using
mypywithmatplotlibversion 3.8.0. When callingplt.show(), mypy reports the following error:Reproducible Example
I have created a minimal reproducible example to demonstrate the issue:
Environment Information
Python Version: 3.11.1
Matplotlib Version: 3.8.0
Mypy Version: 1.5.1
Operating System: Windows
Expected Outcome
I expect that no error should be reported by mypy when calling plt.show() as it has not produced errors in previous versions of matplotlib.
Steps Taken:
I have tried updating both mypy and matplotlib to their latest versions using pip install --upgrade mypy matplotlib. The issue still persists.
ksunden commentedon Sep 26, 2023
Note also that type hints are new for version 3.8.0, which is why previous versions would not have flagged this.
hhoppe commentedon Sep 26, 2023
@ksunden All your comments are right-on. I had forgotten that a
pyproject.tomlfile containsstrict = true.Just now, I edited
pyplot.pyto have:and the
mypy"error" goes away.Would that be an appropriate PR?
Thanks.
ksunden commentedon Sep 27, 2023
I guess I'd be okay with that... I'm personally don't like
no-untyped-callas an error to flag, and if it weren't for such, would probably prefer to just leave things like this untyped... (I think untyped is preferable toAnyjust being sprinkled about, in general)But the pragmatic answer is probably to add something so that it doesn't flag for users.
I'm 50/50 on whether to go with
NoneorAny, as I think backends should not have a return for the pyplot_show function (based on other type hints/docstrings), but if it does return, we will return whatever it gives us... (actually I tried it and mypy doesn't complain about the return when we say the return type is None)I will note that
Anyas a return is also flagged by--strict, though not in calling code, only if we did that when running against mpl itself, which we are still quite far from being able to do properly.