Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jul 1, 2025

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

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
Member

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

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
Member

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

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
Member Author

Choose a reason for hiding this comment

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

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
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
3 participants