Skip to content

Commit

Permalink
fix(typing): Relax dict annotations in channels.py (#3573)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned authored Sep 6, 2024
1 parent a7c227b commit df14929
Show file tree
Hide file tree
Showing 6 changed files with 5,497 additions and 5,790 deletions.
5,348 changes: 2,597 additions & 2,751 deletions altair/vegalite/v5/schema/channels.py

Large diffs are not rendered by default.

3,676 changes: 1,787 additions & 1,889 deletions altair/vegalite/v5/schema/core.py

Large diffs are not rendered by default.

2,236 changes: 1,090 additions & 1,146 deletions altair/vegalite/v5/schema/mixins.py

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions tests/vegalite/v5/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,24 @@ def test_when_multiple_fields():
)


def test_when_typing(cars) -> None:
color = (
alt.when(alt.datum.Weight_in_lbs >= 3500)
.then(alt.value("black"))
.otherwise(alt.value("white"))
)
source = cars
chart = ( # noqa: F841
alt.Chart(source)
.mark_rect()
.encode(
x=alt.X("Cylinders:N").axis(labelColor=color),
y=alt.Y("Origin:N", axis=alt.Axis(tickColor=color)),
color=color,
)
)


@pytest.mark.parametrize(
("channel", "then", "otherwise"),
[
Expand Down
3 changes: 2 additions & 1 deletion tools/generate_schema_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,8 @@ def vegalite_main(skip_download: bool = False) -> None:
]
ruff_write_lint_format_str(outfile, content)

TypeAliasTracer.update_aliases(("Map", "Mapping[str, Any]"))

files: dict[Path, str | Iterable[str]] = {}

# Generate the core schema wrappers
Expand Down Expand Up @@ -871,7 +873,6 @@ def vegalite_main(skip_download: bool = False) -> None:
f"Tracer cache collected {TypeAliasTracer.n_entries!r} entries."
)
print(msg)
TypeAliasTracer.update_aliases(("Map", "Mapping[str, Any]"))
TypeAliasTracer.write_module(
fp_typing, "OneOrSeq", header=HEADER, extra=TYPING_EXTRA
)
Expand Down
6 changes: 3 additions & 3 deletions tools/schemapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"string": "str",
"number": "float",
"integer": "int",
"object": "dict",
"object": "Map",
"boolean": "bool",
"array": "list",
"null": "None",
Expand Down Expand Up @@ -159,7 +159,7 @@ def is_cached(self, tp: str, /) -> bool:
Currently used as a sort key, to place literals/aliases last.
"""
return tp in self._literals_invert or tp in self._literals
return tp in self._literals_invert or tp in self._literals or tp in self._aliases # fmt: skip

def write_module(
self, fp: Path, *extra_all: str, header: LiteralString, extra: LiteralString
Expand Down Expand Up @@ -449,7 +449,7 @@ def get_python_type_representation( # noqa: C901
)
)
type_representations.extend(options)
elif self.is_object():
elif self.is_object() and not for_type_hints:
type_representations.append("dict")
elif self.is_array():
# A list is invariant in its type parameter. This means that e.g.
Expand Down

0 comments on commit df14929

Please sign in to comment.