[Bug]: No overload variant of "__getitem__" of "Spines" matches argument type "slice" [call-overload] · Issue #26808 · matplotlib/matplotlib · GitHub
Skip to content

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

Description

@jklaise

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:

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions