Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 12 additions & 12 deletions pytype/pyi/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2852,11 +2852,11 @@ def g(x: Alias[str]) -> str: ...""",
"""
from typing import TypeVar

Alias = list[list[T]]

S = TypeVar('S')
T = TypeVar('T')

Alias = list[list[T]]

def f(x: list[list[S]]) -> S: ...
def g(x: list[list[str]]) -> str: ...""",
)
Expand All @@ -2871,10 +2871,10 @@ def f(x: DictAlias[str]) -> None: ...""",
"""
from typing import TypeVar

DictAlias = dict[int, V]

V = TypeVar('V')

DictAlias = dict[int, V]

def f(x: dict[int, str]) -> None: ...""",
)

Expand All @@ -2889,11 +2889,11 @@ def f(x: Alias[K, V]) -> Dict[K, V]: ...""",
"""
from typing import TypeVar

Alias = list[dict[K, V]]

K = TypeVar('K')
V = TypeVar('V')

Alias = list[dict[K, V]]

def f(x: list[dict[K, V]]) -> dict[K, V]: ...""",
)

Expand All @@ -2908,11 +2908,11 @@ def f(x: Alias[S, T]) -> Union[S, T]: ...""",
"""
from typing import TypeVar, Union

Alias = Union[list[T], list[S]]

S = TypeVar('S')
T = TypeVar('T')

Alias = Union[list[T], list[S]]

def f(x: Union[list[S], list[T]]) -> Union[S, T]: ...""",
)

Expand All @@ -2926,10 +2926,10 @@ def f(x: Alias[str]) -> None: ...""",
"""
from typing import TypeVar

Alias = dict[T, T]

T = TypeVar('T')

Alias = dict[T, T]

def f(x: dict[str, str]) -> None: ...""",
)

Expand Down Expand Up @@ -3710,11 +3710,11 @@ class X(Generic[T, P]):
"""
from typing import Any, Callable, Generic, ParamSpec, TypeVar

x: X[int, Any]

P = ParamSpec('P')
T = TypeVar('T')

x: X[int, Any]

class X(Generic[T, P]):
f: Callable[P, int]
x: T
Expand Down
2 changes: 1 addition & 1 deletion pytype/pytd/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ def VisitTypeDeclUnit(self, node):

sections = [
imports,
self._FormatTypeParams(self.old_node.type_params),
aliases,
constants,
self._FormatTypeParams(self.old_node.type_params),
node.classes,
node.functions,
]
Expand Down
8 changes: 4 additions & 4 deletions pytype/pytd/visitors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,19 +1224,19 @@ class X(Generic[T]): ...
expected_one = textwrap.dedent("""
from typing import Any, TypeVar

foo.x: Any

T = TypeVar('T')

foo.x: Any

class foo.X(Generic[T]): ...
""").strip()
expected_two = textwrap.dedent("""
from typing import Any, TypeVar

x: Any

T = TypeVar('T')

x: Any

class X(Generic[T]): ...
""").strip()
tree = self.Parse(src)
Expand Down
Loading