Skip to content

[Bug]: No overload variant of "__getitem__" of "Spines" matches argument type "slice" [call-overload] #26808

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
jklaise opened this issue Sep 18, 2023 · 0 comments · Fixed by #26811
Milestone

Comments

@jklaise
Copy link

jklaise commented Sep 18, 2023

Bug summary

Following the docs on Spines, specifically this pattern:

spines[:].set_visible(False)

leads to a mypy error:

error: No overload variant of "__getitem__" of "Spines" matches argument type "slice"  [call-overload]
note: Possible overload variants:
note:     def __getitem__(self, str, /) -> Spine
note:     def __getitem__(self, list[str], /) -> SpinesProxy

Code for reproduction

import matplotlib.pyplot as plt

ax = plt.gca()
ax.spines[:].set_visible(False)

Actual outcome

error: No overload variant of "__getitem__" of "Spines" matches argument type "slice"  [call-overload]
note: Possible overload variants:
note:     def __getitem__(self, str, /) -> Spine
note:     def __getitem__(self, list[str], /) -> SpinesProxy

Expected outcome

mypy passes the above code as correctly typed.

Fix would likely be to define an overload for a slice type here:

class Spines(MutableMapping[str, Spine]):

Additional information

No response

Operating system

No response

Matplotlib Version

3.8.0

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

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

Successfully merging a pull request may close this issue.

4 participants