From b9b8cf9e25b5d7818786339ba0a811e3e4af6806 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 28 Oct 2023 13:08:50 -0400 Subject: [PATCH 1/2] Visit PEP 695 nodes in `get_children()` --- ChangeLog | 5 +++-- astroid/nodes/scoped_nodes/scoped_nodes.py | 3 +++ tests/test_type_params.py | 10 ++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c3958f186a..1b77f3cba2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,9 +13,10 @@ What's New in astroid 3.0.2? ============================ Release date: TBA -* Fix crashes linting code using PEP 695 (Python 3.12) generic type syntax. +* Include PEP 695 (Python 3.12) generic type syntax nodes in ``get_children()``, + allowing checkers to visit them. - Closes pylint-dev/pylint#9098 + Refs pylint-dev/pylint#9193 What's New in astroid 3.0.1? diff --git a/astroid/nodes/scoped_nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes/scoped_nodes.py index 21bad2fecc..e8b1aef4f1 100644 --- a/astroid/nodes/scoped_nodes/scoped_nodes.py +++ b/astroid/nodes/scoped_nodes/scoped_nodes.py @@ -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 @@ -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 diff --git a/tests/test_type_params.py b/tests/test_type_params.py index afc38b14bc..6398f78ade 100644 --- a/tests/test_type_params.py +++ b/tests/test_type_params.py @@ -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) From f7e0151da9c2d29c16546f52a9e289ea4cbd66c4 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 28 Oct 2023 13:37:15 -0400 Subject: [PATCH 2/2] Move changelog --- ChangeLog | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b77f3cba2..f6cf04df14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,16 +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 -* 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.1?