Title: Automagically set the stacklevel on warnings. by anntzer · Pull Request #11298 · matplotlib/matplotlib · GitHub
Open Graph Title: Automagically set the stacklevel on warnings. by anntzer · Pull Request #11298 · matplotlib/matplotlib
X Title: Automagically set the stacklevel on warnings. by anntzer · Pull Request #11298 · matplotlib/matplotlib
Description: There are many places in Matplotlib where it is impossible to set a static stacklevel on warnings that works in all cases, because a same function may either be called directly or via some wrapper (e.g. pyplot). Instead, compute the stacklevel by walking the stack. Given that warnings refer to conditions that should, well, be avoided, I believe we don't need to worry too much about the runtime cost. As an example, use this mechanism for the "ambiguous second argument to plot" warning. Now both plt.gca().plot("x", "y", data={"x": 1, "y": 2}) and plt.plot("x", "y", data={"x": 1, "y": 2}) emit a warning that refers to the relevant line in the user source, whereas previously the second snippet would refer to the pyplot wrapper, which is irrelevant to the user. Note that this only works from source, not from IPython, as the latter uses exec and AFAICT there is no value of stacklevel that correctly refers to the string being exec'd. Of course, the idea would be to ultimately use this throughout the codebase. PR Summary PR Checklist Has Pytest style unit tests Code is PEP 8 compliant New features are documented, with examples if plot related Documentation is sphinx and numpydoc compliant Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there) Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way
Open Graph Description: There are many places in Matplotlib where it is impossible to set a static stacklevel on warnings that works in all cases, because a same function may either be called directly or via some wrapper ...
X Description: There are many places in Matplotlib where it is impossible to set a static stacklevel on warnings that works in all cases, because a same function may either be called directly or via some wrapper ...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/11298
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:656ad8be-06ad-1d1d-e77e-12bf4ab2cdc5 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E48A:3FC274:3703F4:4BF309:6A533A26 |
| html-safe-nonce | 6249f0ec5f02f1a20bb16c18b91a51dc08447e3596aa0fec2618fa26e8da07f2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDhBOjNGQzI3NDozNzAzRjQ6NEJGMzA5OjZBNTMzQTI2IiwidmlzaXRvcl9pZCI6IjY1NDE3NDUzODQxNjY5OTY1MTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e84cdeda6af9755a040d580fae94c7b0ca684cdbcd90325da11546988dc6bcd6 |
| hovercard-subject-tag | pull_request:190154447 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/matplotlib/matplotlib/pull/11298/files |
| twitter:image | https://avatars.githubusercontent.com/u/1322974?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1322974?s=400&v=4 |
| og:image:alt | There are many places in Matplotlib where it is impossible to set a static stacklevel on warnings that works in all cases, because a same function may either be called directly or via some wrapper ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| 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