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
7 changes: 4 additions & 3 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ What's New in astroid 3.1.0?
============================
Release date: TBA

* Include PEP 695 (Python 3.12) generic type syntax nodes in ``get_children()``,
allowing checkers to visit them.

Refs pylint-dev/pylint#9193


What's New in astroid 3.0.2?
============================
Release date: TBA

* Fix crashes linting code using PEP 695 (Python 3.12) generic type syntax.

Closes pylint-dev/pylint#9098


What's New in astroid 3.0.1?
Expand Down
3 changes: 3 additions & 0 deletions astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,7 @@ def get_children(self):

if self.returns is not None:
yield self.returns
yield from self.type_params

yield from self.body

Expand Down Expand Up @@ -2936,6 +2937,8 @@ def get_children(self):
yield from self.bases
if self.keywords is not None:
yield from self.keywords
yield from self.type_params

yield from self.body

@cached_property
Expand Down
10 changes: 10 additions & 0 deletions tests/test_type_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,13 @@ def test_type_param() -> None:
assert isinstance(class_node.type_params[0], TypeVar)
assert class_node.type_params[0].name.name == "T"
assert class_node.type_params[0].bound is None


def test_get_children() -> None:
func_node = extract_node("def func[T]() -> T: ...")
func_children = tuple(func_node.get_children())
assert isinstance(func_children[2], TypeVar)

class_node = extract_node("class MyClass[T]: ...")
class_children = tuple(class_node.get_children())
assert isinstance(class_children[0], TypeVar)