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

refactor(typing): Reuse generated Literal aliases in api #3464

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Changes from all commits
Commits
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
37 changes: 19 additions & 18 deletions altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@
InlineDataset,
)
from altair.expr.core import Expression, GetAttrExpression
from .schema._typing import (
ImputeMethod_T,
SelectionType_T,
SelectionResolution_T,
SingleDefUnitChannel_T,
StackOffset_T,
)

ChartDataType: TypeAlias = Optional[Union[DataType, core.Data, str, core.Generator]]

Expand Down Expand Up @@ -505,9 +512,7 @@ def param(
return parameter


def _selection(
type: Optional[Literal["interval", "point"]] = Undefined, **kwds
) -> Parameter:
def _selection(type: Optional[SelectionType_T] = Undefined, **kwds) -> Parameter:
# We separate out the parameter keywords from the selection keywords

select_kwds = {"name", "bind", "value", "empty", "init", "views"}
Expand Down Expand Up @@ -537,9 +542,7 @@ def _selection(
message="""'selection' is deprecated.
Use 'selection_point()' or 'selection_interval()' instead; these functions also include more helpful docstrings."""
)
def selection(
type: Optional[Literal["interval", "point"]] = Undefined, **kwds
) -> Parameter:
def selection(type: Optional[SelectionType_T] = Undefined, **kwds) -> Parameter:
"""
Users are recommended to use either 'selection_point' or 'selection_interval' instead, depending on the type of parameter they want to create.

Expand Down Expand Up @@ -568,10 +571,10 @@ def selection_interval(
bind: Optional[Binding | str] = Undefined,
empty: Optional[bool] = Undefined,
expr: Optional[str | Expr | Expression] = Undefined,
encodings: Optional[list[str]] = Undefined,
encodings: Optional[list[SingleDefUnitChannel_T]] = Undefined,
on: Optional[str] = Undefined,
clear: Optional[str | bool] = Undefined,
resolve: Optional[Literal["global", "union", "intersect"]] = Undefined,
resolve: Optional[SelectionResolution_T] = Undefined,
mark: Optional[Mark] = Undefined,
translate: Optional[str | bool] = Undefined,
zoom: Optional[str | bool] = Undefined,
Expand Down Expand Up @@ -680,11 +683,11 @@ def selection_point(
bind: Optional[Binding | str] = Undefined,
empty: Optional[bool] = Undefined,
expr: Optional[Expr] = Undefined,
encodings: Optional[list[str]] = Undefined,
encodings: Optional[list[SingleDefUnitChannel_T]] = Undefined,
fields: Optional[list[str]] = Undefined,
on: Optional[str] = Undefined,
clear: Optional[str | bool] = Undefined,
resolve: Optional[Literal["global", "union", "intersect"]] = Undefined,
resolve: Optional[SelectionResolution_T] = Undefined,
toggle: Optional[str | bool] = Undefined,
nearest: Optional[bool] = Undefined,
**kwds,
Expand Down Expand Up @@ -1853,9 +1856,7 @@ def transform_impute(
frame: Optional[list[int | None]] = Undefined,
groupby: Optional[list[str | FieldName]] = Undefined,
keyvals: Optional[list[Any] | ImputeSequence] = Undefined,
method: Optional[
Literal["value", "mean", "median", "max", "min"] | ImputeMethod
] = Undefined,
method: Optional[ImputeMethod_T | ImputeMethod] = Undefined,
value=Undefined,
) -> Self:
"""
Expand Down Expand Up @@ -2378,7 +2379,7 @@ def transform_stack(
as_: str | FieldName | list[str],
stack: str | FieldName,
groupby: list[str | FieldName],
offset: Optional[Literal["zero", "center", "normalize"]] = Undefined,
offset: Optional[StackOffset_T] = Undefined,
sort: Optional[list[SortField]] = Undefined,
) -> Self:
"""
Expand Down Expand Up @@ -3061,7 +3062,7 @@ def interactive(
copy of self, with interactive axes added

"""
encodings = []
encodings: list[SingleDefUnitChannel_T] = []
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only annotated the 4x of these to satisfy mypy.

if bind_x:
encodings.append("x")
if bind_y:
Expand Down Expand Up @@ -3351,7 +3352,7 @@ def interactive(
copy of self, with interactive axes added

"""
encodings = []
encodings: list[SingleDefUnitChannel_T] = []
if bind_x:
encodings.append("x")
if bind_y:
Expand Down Expand Up @@ -3448,7 +3449,7 @@ def interactive(
copy of self, with interactive axes added

"""
encodings = []
encodings: list[SingleDefUnitChannel_T] = []
if bind_x:
encodings.append("x")
if bind_y:
Expand Down Expand Up @@ -3547,7 +3548,7 @@ def interactive(
copy of self, with interactive axes added

"""
encodings = []
encodings: list[SingleDefUnitChannel_T] = []
if bind_x:
encodings.append("x")
if bind_y:
Expand Down