GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — MNT: Move "backend" from a regular rcParams dict entry to a class attribute by timhoffm · Pull Request #31792 · matplotlib/matplotlib Conversation
|
| def _ensure_has_backend(self): | ||
| """ | ||
| Ensure that a "backend" entry exists. | ||
|
|
||
| Normally, the default matplotlibrc file contains *no* entry for "backend" (the | ||
| corresponding line starts with ##, not #; we fill in _auto_backend_sentinel | ||
| in that case. However, packagers can set a different default backend | ||
| (resulting in a normal `#backend: foo` line) in which case we should *not* | ||
| fill in _auto_backend_sentinel. | ||
| """ | ||
| dict.setdefault(self, "backend", rcsetup._auto_backend_sentinel) |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Note: _ensure_has_backend() is not needed anymore, because the backend is stored in the class attribute RcParams._backend and thus always available.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| orig = dict(rcParams.copy()) | ||
| del orig['backend'] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Note: The dict conversion was only needed to be able to drop the backend entry. Since that doesn't exist anymore, we don't need the dict conversion.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
9bd416e to
540d1a4
Compare
| return RcParams._backend | ||
| return dict.__getitem__(self, key) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I suppose these two lines don't need to change, as _get does handle this case. It's a tiny bit more optimized this way, but I'm torn on whether to preserve the symmetry with __setitem__ ending with _set.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
_get is the semi-public way to retrieve bare rcParams values without triggering any logic. It handles "backend" for backward-compatibility, but we will deprecate _get("backend") since "backend" will not be a regular rcParam entry. As such we should internally not rely on _get("backend") but always fetch the value from it's actual source RcParams._backend.
For the second line, yes let's semantically rely on _get here. One can argue either way : __getitem__ and _get being both the interface to the internal data structure - with and without checks. Or one can argue that _get is the only interface to the internal datastructure and __getitem__ builds logic on top of that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ribute Working towards matplotlib#31791. > rcParams should be only configuration, not state; i.e. wrt. backend, it > can hold the desired backend and backend priorities, but it should not > hold the currently active backend or trigger backend selection as a > side-effect. The latter causes a lot of complexity in rcParams. This PR is the first step in the migration strategy outlined there: > Make the backend a RcParams class attribute and do not hold > "backend" as a regular dict entry. There can only be one backend, > so putting that value in a class attribute `RcParams._backend` makes > sense. This already reduces the complexity as we don't need special > handling to sync/copy the value when rcParams are bulk-replaced > (loading from file or rc_context). Instead add special logic to keep > behavioral backward compatibility with the dict API > (`rcParams["backend"]` / `rcParams._get("backend")` / > `"rcParams._set("backend", val)`). Note on API compatibility: This PR limits itself to the known typical dict-API usages in the context of backend handling. I've refrained from trying to fully replicate dict behavior of a "virtual" "backend" parameter, i.e. `len(rcParams)` / `rcParams.keys()` / `rcParams.values()` / `rcParams.items()` do not contain "backend" anymore. I would be willing to accept this level of API breakage. If deemed critical, we could add compatibility shims for that too.
540d1a4 to
df49f80
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.