8000 [ENH]: More accurate type stub for `plt.subplots` like VSCode did before. · Issue #28226 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[ENH]: More accurate type stub for plt.subplots like VSCode did before. #28226
Closed as not planned
@cesaryuan

Description

@cesaryuan

Problem

Before matplotlib 3.8, VSCode embedded its type stubs for matplotlib. At that time, the typehint of plt.subplots is better than the typehint provided by matplotlib itself. You can see the differences below:

Let's see the embedded typehint for plt.subplots. I made it available by changing the Matplotlib version to 3.7. It can identify the ax type correctly.

However, after upgrading to matplotlib 3.8. The VSCode use the type stub provided by matplotlib instead of the one embedded by itself. And it cannot get the corrent type for ax.

image
image

Proposed solution

Adapt the type stub provided by VSCode. You can see them in https://github.com/microsoft/python-type-stubs/blob/102c1448f7504d6450a221ae9c29a260fa741a30/matplotlib/pyplot.pyi#L200C1-L209C30.

I tried just putting the pyplot.pyi file in the pyplot.py folder. It works. So maybe we can do it in repo.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0