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

is_generator correctly considers Yield nodes in AugAssign nodes #877

Merged
merged 1 commit into from
Jan 1, 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
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ Release Date: TBA

Close PyCQA/pylint#3686

* ``is_generator`` correctly considers `Yield` nodes in `AugAssign` nodes

This fixes a false positive with the `assignment-from-no-return` pylint check.

Close PyCQA/pylint#3904


What's New in astroid 2.4.2?
============================
Expand Down
5 changes: 5 additions & 0 deletions astroid/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,11 @@ def get_children(self):
yield self.target
yield self.value

def _get_yield_nodes_skip_lambdas(self):
"""An AugAssign node can contain a Yield node in the value"""
yield from self.value._get_yield_nodes_skip_lambdas()
yield from super()._get_yield_nodes_skip_lambdas()


class Repr(NodeNG):
"""Class representing an :class:`ast.Repr` node.
Expand Down
11 changes: 11 additions & 0 deletions tests/unittest_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,5 +1360,16 @@ def paused_iter(iterable):
assert bool(node.is_generator())


def test_is_generator_for_yield_in_aug_assign():
code = """
def test():
buf = ''
while True:
buf += yield
"""
node = astroid.extract_node(code)
assert bool(node.is_generator())


if __name__ == "__main__":
unittest.main()