diff --git a/altair/__init__.py b/altair/__init__.py index 3b49f05d4..d9adb730f 100644 --- a/altair/__init__.py +++ b/altair/__init__.py @@ -674,7 +674,7 @@ def __getattr__(name: str) -> _Any: alternative="altair.theme", stacklevel=3, ) - return theme.themes + return theme._themes else: msg = f"module {__name__!r} has no attribute {name!r}" raise AttributeError(msg) diff --git a/altair/theme.py b/altair/theme.py index ce0d7ba31..feacc1a91 100644 --- a/altair/theme.py +++ b/altair/theme.py @@ -78,7 +78,7 @@ ViewBackgroundKwds, ViewConfigKwds, ) -from altair.vegalite.v5.theme import themes +from altair.vegalite.v5.theme import themes as _themes if TYPE_CHECKING: import sys @@ -174,7 +174,6 @@ "names", "options", "register", - "themes", "unregister", ] @@ -238,9 +237,9 @@ def custom_theme() -> theme.ThemeConfig: # HACK: See for `LiteralString` requirement in `name` # https://github.com/vega/altair/pull/3526#discussion_r1743350127 def decorate(func: Plugin[ThemeConfig], /) -> Plugin[ThemeConfig]: - themes.register(name, func) + _themes.register(name, func) if enable: - themes.enable(name) + _themes.enable(name) @_wraps(func) def wrapper(*args: P.args, **kwargs: P.kwargs) -> ThemeConfig: @@ -258,14 +257,14 @@ def unregister(name: LiteralString) -> Plugin[ThemeConfig]: Parameters ---------- name - Unique name assigned in ``alt.theme.themes``. + Unique name assigned during ``alt.theme.register``. Raises ------ TypeError When ``name`` has not been registered. """ - plugin = themes.register(name, None) + plugin = _themes.register(name, None) if plugin is None: msg = ( f"Found no theme named {name!r} in registry.\n" @@ -277,9 +276,9 @@ def unregister(name: LiteralString) -> Plugin[ThemeConfig]: return plugin -enable = themes.enable -get = themes.get -names = themes.names +enable = _themes.enable +get = _themes.get +names = _themes.names active: str """Return the name of the currently active theme.""" options: dict[str, Any] @@ -296,9 +295,9 @@ def __getattr__(name: Literal["active"]) -> str: ... # type: ignore[misc] def __getattr__(name: Literal["options"]) -> dict[str, Any]: ... # type: ignore[misc] def __getattr__(name: str) -> Any: if name == "active": - return themes.active + return _themes.active elif name == "options": - return themes.options + return _themes.options else: msg = f"module {__name__!r} has no attribute {name!r}" raise AttributeError(msg) diff --git a/doc/user_guide/api.rst b/doc/user_guide/api.rst index 0cb91f6ae..d3c08f547 100644 --- a/doc/user_guide/api.rst +++ b/doc/user_guide/api.rst @@ -186,7 +186,6 @@ Theme names options register - themes unregister ThemeConfig AreaConfigKwds diff --git a/tests/utils/test_deprecation.py b/tests/utils/test_deprecation.py index cbc13dc5d..d1410f13c 100644 --- a/tests/utils/test_deprecation.py +++ b/tests/utils/test_deprecation.py @@ -58,4 +58,4 @@ def test_deprecated_import(): with catch_warnings(): filterwarnings("ignore", category=AltairDeprecationWarning) - assert alt.themes == alt.theme.themes + assert alt.themes == alt.theme._themes diff --git a/tests/vegalite/test_common.py b/tests/vegalite/test_common.py index 69c173b97..0ea5b049b 100644 --- a/tests/vegalite/test_common.py +++ b/tests/vegalite/test_common.py @@ -20,9 +20,9 @@ def basic_spec(): def make_final_spec(alt, basic_spec): - from altair.theme import themes + from altair.theme import _themes - theme = themes.get() + theme = _themes.get() assert theme spec = theme() spec.update(basic_spec) @@ -70,12 +70,12 @@ def test_basic_chart_from_dict(alt, basic_spec): @pytest.mark.parametrize("alt", [v5]) def test_theme_enable(alt, basic_spec): - from altair.theme import themes + from altair.theme import _themes - active_theme = themes.active + active_theme = _themes.active try: - themes.enable("none") + _themes.enable("none") chart = alt.Chart.from_dict(basic_spec) dct = chart.to_dict() @@ -88,7 +88,7 @@ def test_theme_enable(alt, basic_spec): assert dct == basic_spec finally: # reset the theme to its initial value - themes.enable(active_theme) # pyright: ignore[reportArgumentType] + _themes.enable(active_theme) # pyright: ignore[reportArgumentType] @pytest.mark.parametrize("alt", [v5]) diff --git a/tests/vegalite/v5/test_theme.py b/tests/vegalite/v5/test_theme.py index 484d6d252..da7c134ba 100644 --- a/tests/vegalite/v5/test_theme.py +++ b/tests/vegalite/v5/test_theme.py @@ -78,8 +78,8 @@ def test_theme_register_decorator() -> None: def custom_theme() -> ThemeConfig: return {"height": 400, "width": 700} - assert theme.themes.active == "unique name" == theme.active - registered = theme.themes.get() + assert theme._themes.active == "unique name" == theme.active + registered = theme._themes.get() assert registered is not None assert registered == theme.get() assert registered() == {"height": 400, "width": 700} == custom_theme() @@ -93,7 +93,7 @@ def custom_theme() -> ThemeConfig: assert theme.active == "big square" fn = theme.unregister("big square") assert fn() == custom_theme() - assert theme.active == theme.themes.active + assert theme.active == theme._themes.active # BUG: https://github.com/vega/altair/issues/3619 # assert theme.active != "big square"