Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typing): Fully annotate api.py #3508

Merged
merged 23 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fde0696
ci(ruff): Add `ANN` rules for `api.py` only
dangotbanned Jul 28, 2024
cb1707e
feat(typing): Complete annotations for most `api` functions
dangotbanned Jul 29, 2024
a32c937
feat(typing): Annotate more expr/params in `api`
dangotbanned Jul 29, 2024
de2fe9f
feat(typing): Various changes to enforce `dict[str, Any]` instead of …
dangotbanned Jul 29, 2024
20f9d85
feat(typing): Misc minor method annotations
dangotbanned Jul 29, 2024
8cfcd5c
feat(typing): Use `ChartType` in all `ChartType` dunder methods
dangotbanned Jul 29, 2024
e20e426
fix(ruff): Ignore some `ANN` rules that won't be fixed
dangotbanned Jul 29, 2024
0184c7f
chore: add pyright ignore from #3492
dangotbanned Jul 29, 2024
3ef1ed6
feat(typing): Improve `ChartType` constructor/factory annotations
dangotbanned Jul 29, 2024
591d322
feat(typing): Annotate remaining functions in `api`
dangotbanned Jul 29, 2024
94ef3a5
feat(typing): Complete `RepeatChart` annotations
dangotbanned Jul 29, 2024
470a490
fix(typing): Resolve Liskov violations
dangotbanned Jul 29, 2024
8287f5e
chore(typing): Update more `dict` -> `dict[str, Any]`
dangotbanned Jul 29, 2024
00985dc
style(ruff): fix whitespace
dangotbanned Jul 29, 2024
831d653
chore: Remove TODO fixed in #3480
dangotbanned Jul 29, 2024
60281f5
fix(typing): Enable `ANN003` and fix all in `api`
dangotbanned Jul 29, 2024
3d3fd1e
fix(typing): Enable `ANN002` and fix all in `api`
dangotbanned Jul 29, 2024
010d4fb
chore(ruff): Add note on `ANN`
dangotbanned Jul 29, 2024
26fd795
Merge branch 'main' into api-more-ann
dangotbanned Jul 29, 2024
8e27862
Merge branch 'main' into api-more-ann
dangotbanned Jul 30, 2024
c5ab6f0
fix(typing): Add missing `FacetChart` annotations
dangotbanned Jul 30, 2024
1803550
Merge branch 'main' into api-more-ann
dangotbanned Jul 30, 2024
18c014e
Merge branch 'main' into api-more-ann
dangotbanned Jul 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion altair/expr/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from __future__ import annotations
from typing import Any

from typing import Any, Union, Dict

from typing_extensions import TypeAlias

from ..utils import SchemaBase


Expand Down Expand Up @@ -232,3 +236,6 @@ def __init__(self, group, name) -> None:

def __repr__(self) -> str:
return f"{self.group}[{self.name!r}]"


IntoExpression: TypeAlias = Union[bool, None, str, OperatorMixin, Dict[str, Any]]
6 changes: 3 additions & 3 deletions altair/utils/_transformed_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

if TYPE_CHECKING:
from altair.utils.core import DataFrameLike
from altair.vegalite.v5.api import ChartType

Scope: TypeAlias = Tuple[int, ...]
FacetMapping: TypeAlias = Dict[Tuple[str, Scope], Tuple[str, Scope]]
Expand Down Expand Up @@ -154,9 +155,7 @@ def transformed_data(chart, row_limit=None, exclude=None):
# The same error appeared when trying it with Protocols for the concat and layer charts.
# This function is only used internally and so we accept this inconsistency for now.
def name_views(
chart: Chart | FacetChart | LayerChart | HConcatChart | VConcatChart | ConcatChart,
i: int = 0,
exclude: Iterable[str] | None = None,
chart: ChartType, i: int = 0, exclude: Iterable[str] | None = None
) -> list[str]:
"""
Name unnamed chart views.
Expand Down Expand Up @@ -193,6 +192,7 @@ def name_views(
else:
return []
else:
subcharts: list[Any]
if isinstance(chart, _chart_class_mapping[LayerChart]):
subcharts = chart.layer
elif isinstance(chart, _chart_class_mapping[HConcatChart]):
Expand Down
2 changes: 1 addition & 1 deletion altair/utils/_vegafusion_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def compile_to_vegafusion_chart_state(
return chart_state


def compile_with_vegafusion(vegalite_spec: dict[str, Any]) -> dict:
def compile_with_vegafusion(vegalite_spec: dict[str, Any]) -> dict[str, Any]:
"""
Compile a Vega-Lite spec to Vega and pre-transform with VegaFusion.

Expand Down
6 changes: 3 additions & 3 deletions altair/utils/compiler.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Callable
from typing import Callable, Dict, Any
from altair.utils import PluginRegistry

# ==============================================================================
# Vega-Lite to Vega compiler registry
# ==============================================================================
VegaLiteCompilerType = Callable[[dict], dict]
VegaLiteCompilerType = Callable[[Dict[str, Any]], Dict[str, Any]]


class VegaLiteCompilerRegistry(PluginRegistry[VegaLiteCompilerType, dict]):
class VegaLiteCompilerRegistry(PluginRegistry[VegaLiteCompilerType, Dict[str, Any]]):
pass
Loading