-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: Mypy not finding the right return type for ax.subplots(...,projection="3d") #27455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
None of the 3d code (or anything else in In at least the short term, if you know better than the type system, there are cases where you may wish to use |
I figured this might be the case, but wanted to flag just to be sure. I appreciate the quick response! |
I'm going to close this as "can't fix" as we are pushing the limits of what a static type checker can do on top of our full leveraging of the dynamicness of Python. |
I you really need to placate static type checkers, you could do
|
@timhoffm Is there anything special you did to make that cast work, or a version limitation? I have just tried to do the exact same thing and Mypy is not recognizing the cast at all. Nothing changes in its output whether the cast is there or not. Python 3.11, matplotlib 3.9.3, mypy 1.13. |
I think the problem is that no toolkits have typing, so casting to an |
@QuLogic Ah, that would explain it, thank you! Ugh. I recently upgraded a bunch of versions of things and suddenly I have all these typing errors. I guess I'll just have to turn typing off through the problematic code. |
Bug summary
Mypy says that an
ax
created byax = fig.add_subplot(..., projection="3d")
is typeAxes
rather than the expectedAxes3D
. This causes type checking Axes3D methods to fail e.g.ax.plot_surface()
. Maybe this is fixed if/whenmpl_toolkits
gets typing stubs?Code for reproduction
Actual outcome
python3.9 -m mypy demo.py
produces:Expected outcome
Expected no
attr-defined
mypy error for callingax.surface() on an
Axes3D`Additional information
This occurs with the latest mypy (1.7.1)
Operating system
Ubuntu 20.04
Matplotlib Version
3.8.2
Matplotlib Backend
TKAgg
Python version
Python 3.9.5
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: