mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00

## Summary Fixes https://github.com/astral-sh/ruff/issues/15812 by visiting the second argument as a type definition. ## Test Plan New F401 tests based on the report. --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
67 lines
1.5 KiB
Python
67 lines
1.5 KiB
Python
"""Regression tests for https://github.com/astral-sh/ruff/issues/15812"""
|
|
|
|
|
|
def f():
|
|
from typing import Union
|
|
|
|
from typing_extensions import TypeAliasType
|
|
|
|
Json = TypeAliasType(
|
|
"Json",
|
|
"Union[dict[str, Json], list[Json], str, int, float, bool, None]",
|
|
)
|
|
|
|
|
|
def f():
|
|
from typing import Union
|
|
|
|
from typing_extensions import TypeAliasType, TypeVar
|
|
|
|
T = TypeVar("T")
|
|
V = TypeVar("V")
|
|
Json = TypeAliasType(
|
|
"Json",
|
|
"Union[dict[str, Json], list[Json], str, int, float, bool, T, V, None]",
|
|
type_params=(T, V),
|
|
)
|
|
|
|
|
|
def f():
|
|
from typing import Union
|
|
|
|
from typing_extensions import TypeAliasType
|
|
|
|
Json = TypeAliasType(
|
|
value="Union[dict[str, Json], list[Json], str, int, float, bool, None]",
|
|
name="Json",
|
|
)
|
|
|
|
|
|
# strictly speaking it's a false positive to emit F401 for both of these, but
|
|
# we can't really be expected to understand that the strings here are type
|
|
# expressions (and type checkers probably wouldn't understand them as type
|
|
# expressions either!)
|
|
def f():
|
|
from typing import Union
|
|
|
|
from typing_extensions import TypeAliasType
|
|
|
|
args = [
|
|
"Json",
|
|
"Union[dict[str, Json], list[Json], str, int, float, bool, None]",
|
|
]
|
|
|
|
Json = TypeAliasType(*args)
|
|
|
|
|
|
def f():
|
|
from typing import Union
|
|
|
|
from typing_extensions import TypeAliasType
|
|
|
|
kwargs = {
|
|
"name": "Json",
|
|
"value": "Union[dict[str, Json], list[Json], str, int, float, bool, None]",
|
|
}
|
|
|
|
Json = TypeAliasType(**kwargs)
|