microsoft / pyright

Static Type Checker for Python
Other
13.04k stars 1.39k forks source link

__getitem__ method not defined on type axis #8336

Closed F-Depi closed 1 month ago

F-Depi commented 1 month ago

Simply attempting to access Axes items produces error complaining about getitem method not defined, but the code seems to work correctly. Here’s a snippet:

image

import matplotlib as plt
fig, axs = plt.subplots(1, 2)
axs[0].plot([1, 2, 3], [4, 5, 6])

Running pyright on neovim.

erictraut commented 1 month ago

Pyright is working correctly here, so this isn't a bug.

This appears to be an issue in the matplotlib library. It includes an embeded stub file matplotlib/axes/_axes.pyi that defines the Axes class. This class definition doesn't include a __getitem__ method, nor do any of its parent classes. If you think that it should include a __getitem__ method, please report the issue to the maintainers of matplotlib.

F-Depi commented 1 month ago

Ok, is there a workaround at least?

erictraut commented 1 month ago

You could add a # type: ignore or # pyright: ignore comment to temporarily suppress the error while you're waiting for a fix from the matplotlib maintainers.