Skip to content

Commit

Permalink
feat: Support alt.theme.(active|options)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Oct 1, 2024
1 parent ef0f263 commit 58da996
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
30 changes: 27 additions & 3 deletions altair/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from __future__ import annotations

from functools import wraps as _wraps
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any
from typing import overload as _overload

from altair.vegalite.v5.schema._config import (
AreaConfigKwds,
Expand Down Expand Up @@ -81,7 +82,7 @@

if TYPE_CHECKING:
import sys
from typing import Callable
from typing import Any, Callable, Literal

if sys.version_info >= (3, 11):
from typing import LiteralString
Expand Down Expand Up @@ -157,7 +158,6 @@
"StepKwds",
"StyleConfigIndexKwds",
"ThemeConfig",
"ThemeConfig",
"TickConfigKwds",
"TimeIntervalStepKwds",
"TimeLocaleKwds",
Expand All @@ -168,9 +168,11 @@
"VariableParameterKwds",
"ViewBackgroundKwds",
"ViewConfigKwds",
"active",
"enable",
"get",
"names",
"options",
"register",
"themes",
"unregister",
Expand Down Expand Up @@ -264,3 +266,25 @@ def unregister(name: LiteralString) -> Plugin[ThemeConfig] | None:
enable = themes.enable
get = themes.get
names = themes.names
active: str
"""Return the name of the currently active theme."""
options: dict[str, Any]
"""Return the current themes options dictionary."""


def __dir__() -> list[str]:
return __all__


@_overload
def __getattr__(name: Literal["active"]) -> str: ...
@_overload
def __getattr__(name: Literal["options"]) -> dict[str, Any]: ...
def __getattr__(name: Literal["active", "options"]) -> str | dict[str, Any]:
if name == "active":
return themes.active
elif name == "options":
return themes.options
else:
msg = f"module {__name__!r} has no attribute {name!r}"
raise AttributeError(msg)
2 changes: 2 additions & 0 deletions doc/user_guide/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ Theme
:toctree: generated/theme/
:nosignatures:

active
enable
get
names
options
register
themes
unregister
Expand Down

0 comments on commit 58da996

Please sign in to comment.