FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Don't expose private styles in style.available by QuLogic · Pull Request #30235 · matplotlib/matplotlib · GitHub

Repository navigation

Don't expose private styles in style.available - #30235

Merged
timhoffm merged 1 commit into
matplotlib:mainfrom
QuLogic:private-style
Jul 7, 2025
Merged

timhoffm merged 1 commit into
matplotlib:mainfrom
QuLogic:private-style

Conversation

QuLogic commented Jul 1, 2025

Copy link
Copy Markdown
Member

PR summary

They remain in style.library, because that's how we look them up, but this prevents them being exposed as something someone might use.

Also, fix reload_library, which was accidentally modifying the original base library information each time.

Fixes itprojects/MasVisGtk#13

PR checklist

Comment thread lib/matplotlib/style/__init__.py Outdated
available[:] = sorted(library.keys())
library.update(_update_user_library(_base_library.copy()))
available[:] = sorted(name for name in library
if not name.startswith('_') or name not in _base_library)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ok, so the idea is that we only exclude "_name" styles that are in the base library. Any other styles in the base library are shown, and any user styles are shown. I got that right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would l go for: Exclude all styles with leading _. Not sure why users would register such styles, but let’s just document this way. It’s more in line with general underscore semantics , e.g. dir() and simpler to implement.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Agreed. What if other libraries need to register their own "private" styles?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

My take: Private styles are those with a leading underscore. Everybody can register and get/use them. They are only not listed under the available styles. This is the same logic as with private attributes/methods.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, the only reason I wrote it this way is because the test adds a _test_ style and looks for it in available. But as I've now fixed reload_library to correctly clean up user styles, I think we can use any name in the test.

They remain in `style.library`, because that's how we look them up, but
this prevents them being exposed as something someone might use.

Also, fix `reload_library`, which was accidentally modifying the
original base library information each time.

Fixes itprojects/MasVisGtk#13

timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ok. Though, I think we should move away from "bunch of functions and variables" to a StyleRegistry concept, similar to ColormapRegistry.

timhoffm modified the milestones: v3.11.0, v3.10.4 Jul 7, 2025

timhoffm commented Jul 7, 2025

Copy link
Copy Markdown
Member

I consider this a bug fix, so pointing to 3.10.x

timhoffm merged commit b6777b1 into matplotlib:main Jul 7, 2025

lumberbot-app Bot commented Jul 7, 2025

Copy link
Copy Markdown

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.10.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 b6777b14cdc1bf4503803eda2df79e7c60b84e6e
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am "Backport PR #30235: Don't expose private styles in style.available"
  1. Push to a named branch:
git push YOURFORK v3.10.x:auto-backport-of-pr-30235-on-v3.10.x
  1. Create a PR against branch v3.10.x, I would have named this PR:

"Backport PR #30235 on branch v3.10.x (Don't expose private styles in style.available)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

timhoffm commented Jul 7, 2025

Copy link
Copy Markdown
Member

Not worth a manual backport.

timhoffm modified the milestones: v3.10.4, v3.11.0 Jul 7, 2025
QuLogic deleted the private-style branch July 7, 2025 18:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exclude underscore-prefixed Matplotlib themes from selection

4 participants


Back | FazBrowse Home | New Git URL