Skip to content

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

Closed
@jklaise

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:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions