GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — MNT: Add provisional get_backend(resolve=False) flag by timhoffm · Pull Request #29039 · matplotlib/matplotlib

Conversation

@timhoffm

@timhoffm timhoffm commented Oct 29, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

The default is resolve=True for now, so that it is completely backward-compatible.

The provisional introduction anticipates planned changes for the backend resolution (#26406 (comment)).

If all plays out as intended, this prolongs the range of releases for the migration: If we start deprecating rcParams._get("backend") say in 3.11, people can immediately switch to get_backend(resolve=False) and their code still runs on 3.10 without version gating.
The worst that can happen is that the introduced flag was not helpful and we remove it again, which is easy because it's provisional.

On a side-note: This also helps with a possible future default change from resolve=True to resolve=False. By making the flag available, users can choose the behavior explicitly, again without (or with lesser version gating) if they don't want to be affected by a default change.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@timhoffm timhoffm added this to the v3.10.0 milestone Oct 29, 2024
@timhoffm
timhoffm force-pushed the get_backend branch 6 times, most recently from 25482d5 to 9640a95 Compare October 29, 2024 16:38
tacaswell
tacaswell reviewed Oct 29, 2024
View reviewed changes
Comment thread lib/matplotlib/__init__.py Outdated


def get_backend():
def get_backend(*, resolve=True):

@tacaswell tacaswell Oct 29, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To bikeshed the name a bit, auto_resolve or force_resolution? "resolve" is not fully obvious to me that this means "should I try to guess the best available back end or not".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@timhoffm timhoffm Oct 29, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking on the name a bit. How do we complete the sentence "If no backend has been selected yet, ..."?

  • "trigger backend resolution" / "resolve the backend": this is the "resolve" namespace. I feel "auto" and "force" do not add information here - "automatically resolve the backend", "force backend resolution" both basically state "do the resolution", there's nothing "automatic" about it other than it selects what's available, but that's already the resolution, there's also no "force" it's just the operation to be done.
    Maybe the "resolution" terminology is a bit heavy?
  • "auto-select a suitable backend": get_backend(auto_select=True)?
  • "activate a suitable backend": get_backend(activate=True)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tacaswell tacaswell Oct 29, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like auto_select the best as it also implies that "one was not set, we did not pick, therefor you get back None"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jklymak jklymak Oct 29, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "resolve" makes sense here? get_backend means "tell me what backend I'm using". "resolve" means choose one so it is not unresolved. That this is the default behaviour of get_backend is the design decision we are trying to reverse?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@timhoffm timhoffm Oct 29, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That this is the default behaviour of get_backend is the design decision we are trying to reverse?

This is not a complete sentence (or rather 1.5 sentences 😄). Not sure I understand what you're asking, but I'll try to answer anyway. The first goal is to provide a high-level API for "get the current backend, but don't resolve if there is no current backend". One currently has to rely on the semi-public rcParams._get('backend'), but #26406 (comment) plans to get away from handling backend logic in rcParams. Therefore, get_backend(resolve=False) will be the replacement for rcParams._get('backend').
Whether or not the default should eventually change or not is a separate discussion that can be had later. It does not interfere with this PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jklymak jklymak Oct 29, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point was just that "resolve" makes sense as the kwarg.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

timhoffm reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@timhoffm timhoffm Oct 30, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still collecting opinions on the parameter name. Prime candidates are resolve and auto_select.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tacaswell tacaswell Oct 30, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the argument against resolve is that unless you know the jargon we use about the auto-select backend, it is not clear what "get the backend, but do not resolve" means, where as "get the backend, but do not run the auto-select logic" is relatively clear.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@timhoffm timhoffm Oct 30, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tacaswell that convinces me. While resolve is slightly more concise, auto_select is easier to understand for people without prior knowledge. -> Changed to auto_select.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jklymak
jklymak reviewed Oct 29, 2024
View reviewed changes
Comment thread lib/matplotlib/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@timhoffm
timhoffm force-pushed the get_backend branch 2 times, most recently from fcdf522 to d29e8b5 Compare October 29, 2024 21:28
jklymak
jklymak approved these changes Oct 29, 2024
View reviewed changes
@timhoffm
MNT: Add provisional get_backend(resolve=False) flag
e13b9e4
The default is `resolve=True` for now, so that this introduction
is completely backward-compatible.

The provisional introduction anticipates planned changes for the
backend resolution (matplotlib#26406 (comment)).

If all plays out as intended, this prolongs the range of releases
for the migration: If we start deprecating `rcParams._get("backend")` say in 3.11, people can immediately switch to
`get_backend(resolve=False)` and their code still runs on 3.10
without version gating.
The worst that can happen is that the introduced flag was not
helpful and we remove it again, which is easy because it's provisional.
@timhoffm
timhoffm force-pushed the get_backend branch from d29e8b5 to e13b9e4 Compare October 30, 2024 08:32
tacaswell
tacaswell approved these changes Oct 30, 2024
View reviewed changes
@tacaswell
tacaswell merged commit 218a42b into matplotlib:main Oct 30, 2024
@timhoffm
timhoffm deleted the get_backend branch October 30, 2024 15:46
@timhoffm

timhoffm commented Oct 30, 2024

Copy link
Copy Markdown
Member Author

Note: I've intentionally not added a what's new note. People can start using this, but it's not my ambition to already push them this way by advertising the new API. As written above, this is mainly in 3.10 so that there are less version-gating issues when the API gets formally introduced in 3.11.

tacaswell reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Jan 14, 2026
@timhoffm
MNT: Deprecate rcParams._get("backend")
f343d24
since 3.10 we have the official API `matplotlib.get_backend
(auto_select=False)`. No problems have been reported and
matplotlib-inline is using it https://github
.com/ipython/matplotlib-inline/pull/38. Therefore, I remove the
provisional status from the auto-select flag.

Additionally, I deprecate the API rcParams._get('backend'), which the
above is replacing.

It seems that `rcParams._get("backend")` is not used anywhere
publically, but let's still be defensive and deprecate.

https://github.com/search?q=%2F%5C._get%5C%28%5B%22%27%5Dbackend%5B%22%27%5D%5C%29%2F+language%3APython+NOT+is%3Afork+NOT+path%3A**%2Fmatplotlib%2F**+NOT+path%3A**%2Fsite-packages**+NOT+path%3A**%2Fpyplot.py&type=code

This is working towards matplotlib#26406.
Follow-up to matplotlib#29039.
@timhoffm timhoffm mentioned this pull request Jan 14, 2026
MNT: Deprecate rcParams._get("backend") #30963
Closed
timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Jan 14, 2026
@timhoffm
MNT: Deprecate rcParams._get("backend")
7e92025
since 3.10 we have the official API `matplotlib.get_backend
(auto_select=False)`. No problems have been reported and
matplotlib-inline is using it https://github
.com/ipython/matplotlib-inline/pull/38. Therefore, I remove the
provisional status from the auto-select flag.

Additionally, I deprecate the API rcParams._get('backend'), which the
above is replacing.

It seems that `rcParams._get("backend")` is not used anywhere
publically, but let's still be defensive and deprecate.

https://github.com/search?q=%2F%5C._get%5C%28%5B%22%27%5Dbackend%5B%22%27%5D%5C%29%2F+language%3APython+NOT+is%3Afork+NOT+path%3A**%2Fmatplotlib%2F**+NOT+path%3A**%2Fsite-packages**+NOT+path%3A**%2Fpyplot.py&type=code

This is working towards matplotlib#26406.
Follow-up to matplotlib#29039.
timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Jan 14, 2026
@timhoffm
MNT: Deprecate rcParams._get("backend")
fc8fb3a
since 3.10 we have the official API `matplotlib.get_backend
(auto_select=False)`. No problems have been reported and
matplotlib-inline is using it https://github
.com/ipython/matplotlib-inline/pull/38. Therefore, I remove the
provisional status from the auto-select flag.

Additionally, I deprecate the API rcParams._get('backend'), which the
above is replacing.

It seems that `rcParams._get("backend")` is not used anywhere
publically, but let's still be defensive and deprecate.

https://github.com/search?q=%2F%5C._get%5C%28%5B%22%27%5Dbackend%5B%22%27%5D%5C%29%2F+language%3APython+NOT+is%3Afork+NOT+path%3A**%2Fmatplotlib%2F**+NOT+path%3A**%2Fsite-packages**+NOT+path%3A**%2Fpyplot.py&type=code

This is working towards matplotlib#26406.
Follow-up to matplotlib#29039.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@tacaswell tacaswell tacaswell approved these changes
@jklymak jklymak jklymak approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

v3.10.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@timhoffm @tacaswell @jklymak
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.