What happened?
While rewriting some alt.condition(s) to alt.when(s) in #3544 I came across some examples that work correctly - but upset a type checker.
Minimal Repro
Code block
import altair as alt
from vega_datasets import data
source = data.cars()
color = (
alt.when(alt.datum.Weight_in_lbs >= 3500)
.then(alt.value("hotpink"))
.otherwise(alt.value("goldenrod"))
)
chart = (
alt.Chart(source, width=300, height=150)
.mark_rect()
.encode(
x=alt.X("Cylinders:N").axis(labelColor=color),
y=alt.Y("Origin:N", axis=alt.Axis(tickColor=color)),
color=color,
)
)
chart
Screenshot
Didn't promise it looks pretty, but the spec validates

Solution
The issue is unrelated to #3552, and can instead reuse the solution from #3458.
Not expecting this will require any runtime changes.
However, it will very likely create a huge diff since so much of the generated code will have changes like below:
Map: TypeAlias = Mapping[str, Any]
before: dict | SchemaBase
after: Map | SchemaBase
Creating an issue for visibility and to note that it will need to be merged before #3544 to avoid needing to ignore typing for examples
What would you like to happen instead?
Not require # type: ignore comments for expected use of public API.
Which version of Altair are you using?
5.4.0, 5.4.1, 5.5.0dev
What happened?
While rewriting some
alt.condition(s) toalt.when(s) in #3544 I came across some examples that work correctly - but upset a type checker.Minimal Repro
Code block
Screenshot
Didn't promise it looks pretty, but the spec validatesSolution
The issue is unrelated to #3552, and can instead reuse the solution from #3458.
Not expecting this will require any runtime changes.
However, it will very likely create a huge diff since so much of the generated code will have changes like below:
Creating an issue for visibility and to note that it will need to be merged before #3544 to avoid needing to ignore typing for examples
What would you like to happen instead?
Not require
# type: ignorecomments for expected use of public API.Which version of Altair are you using?
5.4.0,5.4.1,5.5.0dev