diff options
| author | hippo91 <guillaume.peillex@gmail.com> | 2021-03-13 13:51:49 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-13 13:51:49 +0100 |
| commit | 96e75d8c2331d617896ff176e26bbd91c7a4682c (patch) | |
| tree | 7df19382796040da69d25499633edad5a963bd23 | |
| parent | 45aac900a250dcc7b06d3ea0a66dee1a86377a84 (diff) | |
| parent | 973e22ee939b7329a8b8cd404fc41174d635f417 (diff) | |
| download | astroid-git-96e75d8c2331d617896ff176e26bbd91c7a4682c.tar.gz | |
Merge pull request #919 from cdce8p/fix-classdef-keywords
Iterate over Keywords when using ClassDef.get_children
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | astroid/scoped_nodes.py | 4 | ||||
| -rw-r--r-- | tests/unittest_scoped_nodes.py | 6 |
3 files changed, 13 insertions, 1 deletions
@@ -15,6 +15,10 @@ Release Date: TBA Closes PyCQA/pylint#3974 +* Iterate over ``Keywords`` when using ``ClassDef.get_children`` + + Closes PyCQA/pylint#3202 + What's New in astroid 2.5.1? ============================ diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py index 4c84c516..41aa9e1b 100644 --- a/astroid/scoped_nodes.py +++ b/astroid/scoped_nodes.py @@ -1895,7 +1895,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, node_classes.Statement # by a raw factories # a dictionary of class instances attributes - _astroid_fields = ("decorators", "bases", "body") # name + _astroid_fields = ("decorators", "bases", "keywords", "body") # name decorators = None """The decorators that are applied to this class. @@ -2920,6 +2920,8 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, node_classes.Statement yield self.decorators yield from self.bases + if self.keywords is not None: + yield from self.keywords yield from self.body @decorators_mod.cached diff --git a/tests/unittest_scoped_nodes.py b/tests/unittest_scoped_nodes.py index 8d1cb216..db88dca2 100644 --- a/tests/unittest_scoped_nodes.py +++ b/tests/unittest_scoped_nodes.py @@ -1758,6 +1758,12 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase): cls = astroid["TestKlass"] self.assertEqual(len(cls.keywords), 2) self.assertEqual([x.arg for x in cls.keywords], ["foo", "bar"]) + children = list(cls.get_children()) + assert len(children) == 4 + assert isinstance(children[1], nodes.Keyword) + assert isinstance(children[2], nodes.Keyword) + assert children[1].arg == "foo" + assert children[2].arg == "bar" def test_kite_graph(self): data = """ |
