Skip to content

Commit

Permalink
feat: Raise instead of returning None in unregister
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Oct 1, 2024
1 parent 9bd0316 commit 0d95b44
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 16 additions & 2 deletions altair/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,30 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> ThemeConfig:
return decorate


def unregister(name: LiteralString) -> Plugin[ThemeConfig] | None:
def unregister(name: LiteralString) -> Plugin[ThemeConfig]:
"""
Remove and return a previously registered theme.
Parameters
----------
name
Unique name assigned in ``alt.theme.themes``.
Raises
------
TypeError
When ``name`` has not been registered.
"""
return themes.register(name, None)
plugin = themes.register(name, None)
if plugin is None:
msg = (
f"Found no theme named {name!r} in registry.\n"
f"Registered themes:\n"
f"{names()!r}"
)
raise TypeError(msg)
else:
return plugin


enable = themes.enable
Expand Down
6 changes: 5 additions & 1 deletion tests/vegalite/v5/test_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ def custom_theme() -> ThemeConfig:

assert theme.active == "big square"
fn = theme.unregister("big square")
assert fn is not None
assert fn() == custom_theme()
assert theme.active == theme.themes.active
# BUG: https://github.com/vega/altair/issues/3619
# assert theme.active != "big square"

with pytest.raises(
TypeError, match=r"Found no theme named 'big square' in registry."
):
theme.unregister("big square")


@pytest.mark.parametrize(
("color_code", "valid"),
Expand Down

0 comments on commit 0d95b44

Please sign in to comment.