Skip to content

Commit

Permalink
fix(typing): Resolve some revealed issues
Browse files Browse the repository at this point in the history
- `IntoExpression` change I'll add in a new fix PR
- `OperatorMixin` todo needs an issue
  • Loading branch information
dangotbanned committed Sep 25, 2024
1 parent 17da9d0 commit 21d13e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion altair/expr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,4 @@ def __repr__(self) -> str:
return f"{self.group}[{self.name!r}]"


IntoExpression: TypeAlias = Union[bool, None, str, OperatorMixin, Dict[str, Any]]
IntoExpression: TypeAlias = Union[bool, None, str, float, OperatorMixin, Dict[str, Any]]
14 changes: 10 additions & 4 deletions tests/vegalite/v5/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,13 @@ def test_when_labels_position_based_on_condition() -> None:
# `mypy` will flag structural errors here
cond = when["condition"][0]
otherwise = when["value"]
param_color_py_when = alt.param(
expr=alt.expr.if_(cond["test"], cond["value"], otherwise)
)

# TODO: Open an issue on making `OperatorMixin` generic
# Something like this would be used as the return type for all `__dunder__` methods:
# R = TypeVar("R", Expression, SelectionPredicateComposition)
test = cond["test"]
assert not isinstance(test, alt.PredicateComposition)
param_color_py_when = alt.param(expr=alt.expr.if_(test, cond["value"], otherwise))
assert param_color_py_expr.expr == param_color_py_when.expr

chart = (
Expand Down Expand Up @@ -600,7 +604,9 @@ def test_when_expressions_inside_parameters() -> None:
cond = when_then_otherwise["condition"][0]
otherwise = when_then_otherwise["value"]
expected = alt.expr.if_(alt.datum.b >= 0, 10, -20)
actual = alt.expr.if_(cond["test"], cond["value"], otherwise)
test = cond["test"]
assert not isinstance(test, alt.PredicateComposition)
actual = alt.expr.if_(test, cond["value"], otherwise)
assert expected == actual

text_conditioned = bar.mark_text(
Expand Down

0 comments on commit 21d13e7

Please sign in to comment.