Skip to content
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

refactor: alt.themes -> alt.theme.themes #3618

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open

Conversation

dangotbanned
Copy link
Member

@dangotbanned dangotbanned commented Sep 28, 2024

Need a way to make sense of these and start GH threads:

- 10 total files
- 3 modules named `theme.py`
- 2 modules named `__init__.py`
@dangotbanned dangotbanned added maintenance deprecation Requires a **MINOR** version bump labels Sep 28, 2024
altair/__init__.py Outdated Show resolved Hide resolved
def __getattr__(name: str) -> _Any:
from altair.utils.deprecation import deprecated_warn

if name == "themes":
Copy link
Member Author

Choose a reason for hiding this comment

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

Solution is fine currently, but as soon as we start deprecating other imports it would make sense to generalize

"https://altair-viz.github.io/user_guide/customization.html#chart-themes",
version="5.5.0",
alternative="altair.theme.themes",
stacklevel=3,
Copy link
Member Author

Choose a reason for hiding this comment

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

While I was testing, the default I'd set of 2 didn't report any warnings.

Not sure if that is related to __getattr__ itself, but noting it anyway

@@ -93,7 +93,7 @@

class AreaConfigKwds(TypedDict, total=False):
"""
:class:`AreaConfig` ``TypedDict`` wrapper.
:class:`altair.AreaConfig` ``TypedDict`` wrapper.
Copy link
Member Author

@dangotbanned dangotbanned Sep 29, 2024

Choose a reason for hiding this comment

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

Previously these didn't work as links in the API reference.

Now they do

image

Note

I expect this hasn't come up before since everything has already been in altair.___.

The same will apply for any symbols in altair.(theme|typing)

Comment on lines +264 to +266
enable = themes.enable
get = themes.get
names = themes.names
Copy link
Member Author

Choose a reason for hiding this comment

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

Note

Originally planned for this to be a temporary solution.

Quite surpised at how well aliasing worked:

Docstring

image

API Reference

image

Indistinguishable from an actual function

image

@dangotbanned dangotbanned linked an issue Sep 29, 2024 that may be closed by this pull request
Comment on lines 173 to 191
.. _api-theme:

Theme
-----
.. currentmodule:: altair.theme

.. autosummary::
:toctree: generated/theme/
:nosignatures:

enable
get
names
register
themes
unregister
ThemeConfig
AreaConfigKwds
AutoSizeParamsKwds
Copy link
Member Author

@dangotbanned dangotbanned Sep 30, 2024

Choose a reason for hiding this comment

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

Preview

I think this order makes the most sense.

  • Functions will be the first thing you need
  • The top level config is clearly visible
  • Then further config via ...Kwds.

Earlier versions

a9538bc

a9538bc (#3618)

image

58da996

58da996 (#3618)

image

Updated following 3e6bde8 (#3618)

image

Comment on lines +713 to +715
.. note::

This material was changed considerably with the release of Altair ``5.5.0``.
Copy link
Member Author

Choose a reason for hiding this comment

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

Note

Trying to keep this PR focused to make for an easier review.

I am planning to develop this section further (#3519), but would like to do that in follow-up PRs.

(All still prior to v5.5.0)

@dangotbanned dangotbanned changed the title refactor(DRAFT): alt.themes -> alt.theme.themes refactor: alt.themes -> alt.theme.themes Sep 30, 2024
@dangotbanned dangotbanned marked this pull request as ready for review September 30, 2024 20:18
I added this while experimenting with a more complex `__getattr__`, but don't need it for anything in this version
Comment on lines +668 to +672
deprecated_warn(
"Most of the `ThemeRegistry` API is accessible via `altair.theme`.\n"
"See the updated User Guide for further details:\n"
" https://altair-viz.github.io/user_guide/api.html#theme\n"
" https://altair-viz.github.io/user_guide/customization.html#chart-themes",
Copy link
Member Author

Choose a reason for hiding this comment

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

alt.themes deprecation warning message

altair/theme.py Outdated
Comment on lines 254 to 263
def unregister(name: LiteralString) -> Plugin[ThemeConfig] | None:
"""
Remove and return a previously registered theme.

Parameters
----------
name
Unique name assigned in ``alt.theme.themes``.
"""
return themes.register(name, None)
Copy link
Member Author

Choose a reason for hiding this comment

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

Note

  • More explicit than being part of themes.register
  • This behavior is not part of @alt.theme.register
  • It wouldn't make sense decorating a function with it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation Requires a **MINOR** version bump maintenance
Projects
None yet
1 participant