Skip to content

[Bug]: type annotation of Axes.get_legend() misses None #30318

@bersbersbers

Description

@bersbersbers

Bug summary

Implementation:

def get_legend(self):
"""Return the `.Legend` instance, or None if no legend is defined."""
return self.legend_

Type hints:

def get_legend(self) -> Legend: ...

Proposed change:

- def get_legend(self) -> Legend: ...
+ def get_legend(self) -> Legend | None: ...

Code for reproduction

n/a

Actual outcome

type checkers warn of unnecessary is None checks.

Expected outcome

type checkers should not warn of unnecessary is None checks.

Additional information

No response

Operating system

No response

Matplotlib Version

3.10.3

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good first issueOpen a pull request against these issues if there are no active ones!topic: typing

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions