Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterate over Keywords when using ClassDef.get_children #919

Merged
merged 3 commits into from
Mar 13, 2021
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
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Release Date: TBA

Closes PyCQA/pylint#3974

* Iterate over ``Keywords`` when using ``ClassDef.get_children``

hippo91 marked this conversation as resolved.
Show resolved Hide resolved
Closes PyCQA/pylint#3202


What's New in astroid 2.5.1?
============================
Expand Down
4 changes: 3 additions & 1 deletion astroid/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ def my_meth(self, arg):
# 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.
Expand Down Expand Up @@ -2920,6 +2920,8 @@ def get_children(self):
yield self.decorators

yield from self.bases
if self.keywords is not None:
yield from self.keywords
yield from self.body

@decorators_mod.cached
Expand Down
6 changes: 6 additions & 0 deletions tests/unittest_scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,12 @@ class TestKlass(object, metaclass=TestMetaKlass,
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 = """
Expand Down