Skip to content

Commit

Permalink
feat: Adds ThemeConfig (TypedDict) (#3536)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefan Binder <[email protected]>
  • Loading branch information
dangotbanned and binste authored Sep 22, 2024
1 parent eb6febd commit 712680b
Show file tree
Hide file tree
Showing 18 changed files with 10,121 additions and 772 deletions.
4 changes: 4 additions & 0 deletions altair/typing.py → altair/typing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@
"ChartType",
"EncodeKwds",
"Optional",
"ThemeConfig",
"is_chart_type",
"theme",
]

from altair.typing import theme
from altair.typing.theme import ThemeConfig
from altair.utils.schemapi import Optional
from altair.vegalite.v5.api import ChartType, is_chart_type
from altair.vegalite.v5.schema.channels import (
Expand Down
1 change: 1 addition & 0 deletions altair/typing/theme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from altair.vegalite.v5.schema._config import * # noqa: F403
12 changes: 12 additions & 0 deletions altair/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,21 @@ def decorate(cb: WrapsFunc[R], /) -> WrappedMethod[T, P, R] | WrappedFunc[P, R]:
return decorate


@overload
def update_nested(
original: t.MutableMapping[Any, Any],
update: t.Mapping[Any, Any],
copy: Literal[False] = ...,
) -> t.MutableMapping[Any, Any]: ...
@overload
def update_nested(
original: t.Mapping[Any, Any],
update: t.Mapping[Any, Any],
copy: Literal[True],
) -> t.MutableMapping[Any, Any]: ...
def update_nested(
original: Any,
update: t.Mapping[Any, Any],
copy: bool = False,
) -> t.MutableMapping[Any, Any]:
"""
Expand Down
9 changes: 5 additions & 4 deletions altair/utils/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from __future__ import annotations

import sys
from typing import TYPE_CHECKING, Any, Dict
from typing import TYPE_CHECKING

from .plugin_registry import Plugin, PluginRegistry
from altair.utils.plugin_registry import Plugin, PluginRegistry
from altair.vegalite.v5.schema._config import ThemeConfig

if sys.version_info >= (3, 11):
from typing import LiteralString
Expand All @@ -16,12 +17,12 @@
from altair.utils.plugin_registry import PluginEnabler
from altair.vegalite.v5.theme import AltairThemes, VegaThemes

ThemeType = Plugin[Dict[str, Any]]
ThemeType = Plugin[ThemeConfig]


# HACK: See for `LiteralString` requirement in `name`
# https://github.com/vega/altair/pull/3526#discussion_r1743350127
class ThemeRegistry(PluginRegistry[ThemeType, Dict[str, Any]]):
class ThemeRegistry(PluginRegistry[ThemeType, ThemeConfig]):
def enable(
self, name: LiteralString | AltairThemes | VegaThemes | None = None, **options
) -> PluginEnabler:
Expand Down
Loading

0 comments on commit 712680b

Please sign in to comment.