Skip to content

Commit

Permalink
Add TypeAlias.assigned_stmts() (#2252)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored Jul 16, 2023
1 parent 4c3bebb commit 623482b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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

0 comments on commit 623482b

Please sign in to comment.