Skip to content

[Bug]: Incorrect type annotation for legend handes? #26639

Closed
@mwaskom

Description

@mwaskom

Bug summary

The handles parameter for mpl.legend.Legend is typed as Iterable[Artist], but I believe that legend handles can also be artist tuples to produce a combo legend annotation?

Code for reproduction

# This works anyway

import matplotlib as mpl
import matplotlib.pyplot as plt

f, ax = plt.subplots()
h1 = mpl.lines.Line2D([], [])
h2 = mpl.patches.Patch(alpha=.2)
ax.legend(handles=[(h1, h2)], labels=["combo artist"])

Actual outcome

MyPy error when I pass a list of artist tuples to mpl.legend.Legend.

Expected outcome

I think this is valid matplotlib?

Additional information

Sorry the bug report template isn't the ideal format for this.

Operating system

No response

Matplotlib Version

3.8.0rc1

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