Title: [Bug]: type annotation of `Axes.get_legend()` misses `None` · Issue #30318 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: type annotation of `Axes.get_legend()` misses `None` · Issue #30318 · matplotlib/matplotlib
X Title: [Bug]: type annotation of `Axes.get_legend()` misses `None` · Issue #30318 · matplotlib/matplotlib
Description: Bug summary Implementation: matplotlib/lib/matplotlib/axes/_base.py Lines 2226 to 2228 in b766c96 def get_legend(self): """Return the `.Legend` instance, or None if no legend is defined.""" return self.legend_ Type hints: matplotlib/lib/...
Open Graph Description: Bug summary Implementation: matplotlib/lib/matplotlib/axes/_base.py Lines 2226 to 2228 in b766c96 def get_legend(self): """Return the `.Legend` instance, or None if no legend is defined.""" return ...
X Description: Bug summary Implementation: matplotlib/lib/matplotlib/axes/_base.py Lines 2226 to 2228 in b766c96 def get_legend(self): """Return the `.Legend` instance, or None if no legend is defi...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/30318
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: type annotation of `Axes.get_legend()` misses `None`","articleBody":"### Bug summary\n\nImplementation:\nhttps://github.com/matplotlib/matplotlib/blob/b766c96c36bed6bdea83c61d272d12fb19ac3126/lib/matplotlib/axes/_base.py#L2226-L2228\n\nType hints:\nhttps://github.com/matplotlib/matplotlib/blob/b766c96c36bed6bdea83c61d272d12fb19ac3126/lib/matplotlib/axes/_base.pyi#L228\n\nProposed change:\n```diff\n- def get_legend(self) -\u003e Legend: ...\n+ def get_legend(self) -\u003e Legend | None: ...\n```\n\n### Code for reproduction\n\n```Python\nn/a\n```\n\n### Actual outcome\n\ntype checkers warn of unnecessary `is None` checks.\n\n### Expected outcome\n\ntype checkers should not warn of unnecessary `is None` checks.\n\n### Additional information\n\n_No response_\n\n### Operating system\n\n_No response_\n\n### Matplotlib Version\n\n3.10.3\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n_No response_\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nNone","author":{"url":"https://github.com/bersbersbers","@type":"Person","name":"bersbersbers"},"datePublished":"2025-07-16T06:36:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/30318/matplotlib/issues/30318"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:848b1f39-b83d-ca2d-c6bd-d9ccdb160417 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C8EC:19730C:70413C:98362C:6A51D3D1 |
| html-safe-nonce | 96b5ac4932e5f0f6fc931550721c70ad7f458a6134aeccd4c4433ebe2bcda52d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOEVDOjE5NzMwQzo3MDQxM0M6OTgzNjJDOjZBNTFEM0QxIiwidmlzaXRvcl9pZCI6IjkxOTg1OTE1NDYyMTk0MTg1NzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0fe1c1fab28a6c9193e905b4f584b39e18e98cee7dd8abef7d516145fb8bc3b0 |
| hovercard-subject-tag | issue:3234676882 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/30318/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e399a83dfa9fb0f79aba88515487ff9559363abb631f0e9cdf4d21b37b9b0b10/matplotlib/matplotlib/issues/30318 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e399a83dfa9fb0f79aba88515487ff9559363abb631f0e9cdf4d21b37b9b0b10/matplotlib/matplotlib/issues/30318 |
| og:image:alt | Bug summary Implementation: matplotlib/lib/matplotlib/axes/_base.py Lines 2226 to 2228 in b766c96 def get_legend(self): """Return the `.Legend` instance, or None if no legend is defined.""" return ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bersbersbers |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width