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

Add TypeAlias.assigned_stmts() #2252

Merged
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
13 changes: 13 additions & 0 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Literal,
Optional,
Union,
Expand Down Expand Up @@ -4058,6 +4059,18 @@ def _infer(
) -> Iterator[TypeAlias]:
yield self

assigned_stmts: ClassVar[
Callable[
[
TypeAlias,
AssignName,
InferenceContext | None,
None,
],
Generator[NodeNG, None, None],
]
] = protocols.assign_assigned_stmts


class TypeVar(_base_nodes.AssignTypeNode):
"""Class representing a :class:`ast.TypeVar` node.
Expand Down
2 changes: 1 addition & 1 deletion astroid/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def arguments_assigned_stmts(

@decorators.raise_if_nothing_inferred
def assign_assigned_stmts(
self: nodes.AugAssign | nodes.Assign | nodes.AnnAssign,
self: nodes.AugAssign | nodes.Assign | nodes.AnnAssign | nodes.TypeAlias,
node: node_classes.AssignedStmtsPossibleNode = None,
context: InferenceContext | None = None,
assign_path: list[int] | None = None,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_type_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def test_type_alias() -> None:

assert node.statement() is node

assigned = next(node.assigned_stmts())
assert assigned is node.value


def test_type_param_spec() -> None:
node = extract_node("type Alias[**P] = Callable[P, int]")
Expand Down