Title: [ENH]: Improve typing of Figure.subplots · Issue #28045 · matplotlib/matplotlib · GitHub
Open Graph Title: [ENH]: Improve typing of Figure.subplots · Issue #28045 · matplotlib/matplotlib
X Title: [ENH]: Improve typing of Figure.subplots · Issue #28045 · matplotlib/matplotlib
Description: Bug summary The type stubs for Figure.subplots has two @overloads. One is generic, and the other is specialised for squeeze=False (in which case the return value is always nd.ndarray). But there are also some other cases where the type c...
Open Graph Description: Bug summary The type stubs for Figure.subplots has two @overloads. One is generic, and the other is specialised for squeeze=False (in which case the return value is always nd.ndarray). But there ar...
X Description: Bug summary The type stubs for Figure.subplots has two @overloads. One is generic, and the other is specialised for squeeze=False (in which case the return value is always nd.ndarray). But there ar...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/28045
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: Improve typing of Figure.subplots","articleBody":"### Bug summary\r\n\r\nThe type stubs for Figure.subplots has two `@overloads`. One is generic, and the other is specialised for squeeze=False (in which case the return value is always nd.ndarray). But there are also some other cases where the type could be more accurately inferred.\r\n\r\n### Code for reproduction\r\n\r\n```Python\r\nfrom matplotlib.figure import Figure\r\n\r\nfig = Figure()\r\nreveal_type(fig.subplots())\r\nreveal_type(fig.subplots(2))\r\nreveal_type(fig.subplots(1, 2))\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\nWhen run in mypy:\r\n```\r\ninfer.py:4: note: Revealed type is \"Union[numpy.ndarray[Any, Any], matplotlib.axes.SubplotBase, matplotlib.axes._axes.Axes]\"\r\ninfer.py:5: note: Revealed type is \"Union[numpy.ndarray[Any, Any], matplotlib.axes.SubplotBase, matplotlib.axes._axes.Axes]\"\r\ninfer.py:6: note: Revealed type is \"Union[numpy.ndarray[Any, Any], matplotlib.axes.SubplotBase, matplotlib.axes._axes.Axes]\"\r\n```\r\n\r\n### Expected outcome\r\n\r\n```\r\ninfer.py:4: note: Revealed type is \"Union[matplotlib.axes.SubplotBase, matplotlib.axes._axes.Axes]\"\r\ninfer.py:5: note: Revealed type is \"numpy.ndarray[Any, Any]]\"\r\ninfer.py:6: note: Revealed type is \"numpy.ndarray[Any, Any]]\"\r\n```\r\n\r\n### Additional information\r\n\r\nThe last two examples may be impossible to implement, because you'd need a way to type \"a literal integer != 1\". But the first case is the one I initially ran into. I was able to work around it by replacing it with `fig.add_subplot()`, but that isn't semantically identical.\r\n\r\n### Operating system\r\n\r\nUbuntu\r\n\r\n### Matplotlib Version\r\n\r\n3.8.0\r\n\r\n### Matplotlib Backend\r\n\r\nTkAgg\r\n\r\n### Python version\r\n\r\n3.10.12\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\npip","author":{"url":"https://github.com/bmerry","@type":"Person","name":"bmerry"},"datePublished":"2024-04-08T09:32:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/28045/matplotlib/issues/28045"}
| 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:a17a881e-96dc-2d27-b981-181a78dcd52e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C6B8:18AAA8:C929E9:115745D:6A53AC44 |
| html-safe-nonce | 9063124600c23a5e4f95b74a790a3b2eb9e5b8e63726660a3fe71d97d49edf0c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNkI4OjE4QUFBODpDOTI5RTk6MTE1NzQ1RDo2QTUzQUM0NCIsInZpc2l0b3JfaWQiOiI5MDg3MzA2NDkxMTUzODUzNTA4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 291c1e472e492956f3a2f83eebe34f01b83e0d003edaf9c3de904d04c727fa81 |
| hovercard-subject-tag | issue:2230715764 |
| 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/28045/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f6568f2a1b45215e4b53046afeb050ecd408e8c32423c88ea9c5c56cc67fcb0c/matplotlib/matplotlib/issues/28045 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f6568f2a1b45215e4b53046afeb050ecd408e8c32423c88ea9c5c56cc67fcb0c/matplotlib/matplotlib/issues/28045 |
| og:image:alt | Bug summary The type stubs for Figure.subplots has two @overloads. One is generic, and the other is specialised for squeeze=False (in which case the return value is always nd.ndarray). But there ar... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bmerry |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width