Skip to content

Commit

Permalink
feat(typing): Ban typing.Optional import using ruff (vega#3460)
Browse files Browse the repository at this point in the history
* feat(typing): Ban `typing.Optional` import using `ruff`

The user will see this message ```
altair\utils\data.py:17:5: TID251 `typing.Optional` is banned: Use `Union[T, None]` instead. `typing.Optional` is likely to be confused with `altair.Optional`, which have similar but different semantic meaning. See vega#3449 Found 1 error.
```

Partial fix for vega#3452 (comment)

* fix: typo in message
  • Loading branch information
dangotbanned committed Jul 3, 2024
1 parent 91a1de1 commit 403f1fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions altair/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
TypeVar,
Union,
Dict,
Optional,
overload,
runtime_checkable,
)
Expand Down Expand Up @@ -54,7 +53,7 @@ class SupportsGeoInterface(Protocol):
str, Union[str, Dict[Any, Any], List[Dict[Any, Any]]]
]
ToValuesReturnType: TypeAlias = Dict[str, Union[Dict[Any, Any], List[Dict[Any, Any]]]]
SampleReturnType = Optional[Union[pd.DataFrame, Dict[str, Sequence], "pa.lib.Table"]]
SampleReturnType = Union[pd.DataFrame, Dict[str, Sequence], "pa.lib.Table", None]


def is_data_type(obj: Any) -> TypeIs[DataType]:
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ unfixable= [
[tool.ruff.lint.mccabe]
max-complexity = 18

[tool.ruff.lint.flake8-tidy-imports.banned-api]
# https://docs.astral.sh/ruff/settings/#lint_flake8-tidy-imports_banned-api
"typing.Optional".msg = "Use `Union[T, None]` instead.\n`typing.Optional` is likely to be confused with `altair.Optional`, which have a similar but different semantic meaning.\nSee https://github.com/vega/altair/pull/3449"

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
Expand Down

0 comments on commit 403f1fa

Please sign in to comment.