Skip to content

Commit 96e75d8

Browse files
authored
Merge pull request #919 from cdce8p/fix-classdef-keywords
Iterate over Keywords when using ClassDef.get_children
2 parents 45aac90 + 973e22e commit 96e75d8

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Release Date: TBA
1515

1616
Closes PyCQA/pylint#3974
1717

18+
* Iterate over ``Keywords`` when using ``ClassDef.get_children``
19+
20+
Closes PyCQA/pylint#3202
21+
1822

1923
What's New in astroid 2.5.1?
2024
============================

astroid/scoped_nodes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,7 @@ def my_meth(self, arg):
18951895
# by a raw factories
18961896

18971897
# a dictionary of class instances attributes
1898-
_astroid_fields = ("decorators", "bases", "body") # name
1898+
_astroid_fields = ("decorators", "bases", "keywords", "body") # name
18991899

19001900
decorators = None
19011901
"""The decorators that are applied to this class.
@@ -2920,6 +2920,8 @@ def get_children(self):
29202920
yield self.decorators
29212921

29222922
yield from self.bases
2923+
if self.keywords is not None:
2924+
yield from self.keywords
29232925
yield from self.body
29242926

29252927
@decorators_mod.cached

tests/unittest_scoped_nodes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,12 @@ class TestKlass(object, metaclass=TestMetaKlass,
17581758
cls = astroid["TestKlass"]
17591759
self.assertEqual(len(cls.keywords), 2)
17601760
self.assertEqual([x.arg for x in cls.keywords], ["foo", "bar"])
1761+
children = list(cls.get_children())
1762+
assert len(children) == 4
1763+
assert isinstance(children[1], nodes.Keyword)
1764+
assert isinstance(children[2], nodes.Keyword)
1765+
assert children[1].arg == "foo"
1766+
assert children[2].arg == "bar"
17611767

17621768
def test_kite_graph(self):
17631769
data = """

0 commit comments

Comments
 (0)