Title: Deprecate globals using module-level `__getattr__`. by anntzer · Pull Request #20733 · matplotlib/matplotlib · GitHub
Open Graph Title: Deprecate globals using module-level `__getattr__`. by anntzer · Pull Request #20733 · matplotlib/matplotlib
X Title: Deprecate globals using module-level `__getattr__`. by anntzer · Pull Request #20733 · matplotlib/matplotlib
Description: This PR is mostly just to propose a pattern for defining module-level __getattr__s for deprecating globals. Relying on lru_cache rather than defining variables as global (see change in __init__.py) avoids having to repeat twice the variable name, and allows immediately returning its value without assigning it. It means later accesses will be very slightly slower (because they'll still go through the lru_cache layer), but that should hopefully be negligible, and will mostly concern deprecated variables anyways. One could consider adding a helper API in _api.deprecation that just provides the decoration with @lru_cache and generates the AttributeError message when needed, but that seems rather overkill. (See #20620 (comment), in response to which this was written: I don't have any "magic" idea this time :-), I now think the #10735 isn't really worth it.) The change in deprecation.py allows one to skip obj_name and get a message like "foo is deprecated..." rather than "The foo is deprecated...". PR Summary PR Checklist Has pytest style unit tests (and pytest passes). Is Flake 8 compliant (run flake8 on changed files to check). New features are documented, with examples if plot related. Documentation is sphinx and numpydoc compliant (the docs should build without error). Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all). New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there). API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
Open Graph Description: This PR is mostly just to propose a pattern for defining module-level __getattr__s for deprecating globals. Relying on lru_cache rather than defining variables as global (see change in __init__.py)...
X Description: This PR is mostly just to propose a pattern for defining module-level __getattr__s for deprecating globals. Relying on lru_cache rather than defining variables as global (see change in __init__.py)...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/20733
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:3b25dc8e-6ece-3eca-a542-0e638fbc83ce |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9C50:1D1D40:BE67E5:FED6E7:6A51A96C |
| html-safe-nonce | 45d5aca16cca3e8e58337f875683e35735d9eba978f63735aeacaa74687d69c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QzUwOjFEMUQ0MDpCRTY3RTU6RkVENkU3OjZBNTFBOTZDIiwidmlzaXRvcl9pZCI6IjQwODg3NzMzOTU0NDA4MzkwMjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ec343c0487e91e6001661293ef9b1d8ae6b317ed09aa8aa6810f565431d74295 |
| hovercard-subject-tag | pull_request:696353939 |
| 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/20733/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 | This PR is mostly just to propose a pattern for defining module-level __getattr__s for deprecating globals. Relying on lru_cache rather than defining variables as global (see change in __init__.py)... |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width