From ed60b4e2a8b7185ed1c47823efa64ea631e5fac3 Mon Sep 17 00:00:00 2001 From: dangotbanned <125183946+dangotbanned@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:42:53 +0100 Subject: [PATCH] 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 https://github.com/vega/altair/pull/3449 Found 1 error. ``` Partial fix for https://github.com/vega/altair/pull/3452#discussion_r1663857513 --- altair/utils/data.py | 3 +-- pyproject.toml | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/altair/utils/data.py b/altair/utils/data.py index 8ab46a6f7..61923231c 100644 --- a/altair/utils/data.py +++ b/altair/utils/data.py @@ -14,7 +14,6 @@ TypeVar, Union, Dict, - Optional, overload, runtime_checkable, ) @@ -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]: diff --git a/pyproject.toml b/pyproject.toml index 931c34581..e6affe2ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 similar but different semantic meaning.\nSee https://github.com/vega/altair/pull/3449" + [tool.ruff.format] quote-style = "double" indent-style = "space"