Skip to content

[Bug]: typehint missing for matplotlib Axes #28210

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

Closed
dlefcoe opened this issue May 12, 2024 · 1 comment
Closed

[Bug]: typehint missing for matplotlib Axes #28210

dlefcoe opened this issue May 12, 2024 · 1 comment

Comments

@dlefcoe
Copy link

dlefcoe commented May 12, 2024

Bug summary

plt.subplots in matplotlib 3.8.0 returns tuple[Figure, Any], so Pylance doesn't know the type of ax

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib.axes import Axes        # added this

fig, ax = plt.subplots()
ax: Axes                                # added this

fruits = ['apple', 'blueberry', 'cherry', 'orange']
counts = [40, 100, 30, 55]
colours = ['red', 'blue', 'red', 'orange']

ax.bar(fruits, counts, label=colours, color=colours)

ax.set_ylabel('fruit supply')
ax.set_title('Fruit supply by kind and color')
ax.legend(title='Fruit color')

plt.show()

Actual outcome

The intelisense does not work for ax so it has to be explicitly typehinted.

Expected outcome

The import of Axes and the typehint of ax should not be required.

Additional information

please see this stackoverflow link: https://stackoverflow.com/questions/77368904/methods-and-attributes-do-not-show-when-dot-is-pressed-intellisense

Operating system

windows 11

Matplotlib Version

3.8.0

Matplotlib Backend

TkAgg

Python version

3.12

Jupyter version

No response

Installation

pip

@ksunden
Copy link
Member

ksunden commented May 13, 2024

The short version is "its complicated" and, while we can do better the perfect behavior is not super possible, since this method returns different types based on the value of parameters. Any is a shortcut for "at least it won't yell at users here".

I am going to close this as a duplicate of #27025, And will also respond to your question in #27001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants