diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2021-01-01 15:41:46 +0100 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2021-01-01 16:25:26 +0100 |
commit | c9fd1934e9c49d9052f64439fc7ea82026bce00f (patch) | |
tree | a4c31596cb5f9cd013fbb1c53924a4d403235a1f | |
parent | 58212bd459269da1b9cbf20ff23c3738f4d3dc3d (diff) | |
download | astroid-git-c9fd1934e9c49d9052f64439fc7ea82026bce00f.tar.gz |
``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
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | astroid/node_classes.py | 5 | ||||
-rw-r--r-- | tests/unittest_nodes.py | 11 |
3 files changed, 22 insertions, 0 deletions
@@ -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? ============================ diff --git a/astroid/node_classes.py b/astroid/node_classes.py index 86529e5a..62438e62 100644 --- a/astroid/node_classes.py +++ b/astroid/node_classes.py @@ -2125,6 +2125,11 @@ class AugAssign(mixins.AssignTypeMixin, Statement): 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. diff --git a/tests/unittest_nodes.py b/tests/unittest_nodes.py index 5b6a39e3..d138ee17 100644 --- a/tests/unittest_nodes.py +++ b/tests/unittest_nodes.py @@ -1360,5 +1360,16 @@ def test_is_generator_for_yield_in_if(): 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() |