Skip to content

Commit

Permalink
Make sure that assign nodes can find yield statements in their va…
Browse files Browse the repository at this point in the history
  • Loading branch information
PCManticore committed Aug 10, 2018
1 parent 900a4b8 commit 3f7c4bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
astroid's ChangeLog
===================

What's New in astroid 2.0.4?
============================
Release Date: TBA

* Make sure that assign nodes can find ``yield`` statements in their values

Close PyCQA/pylint#2400

What's New in astroid 2.0.3?
============================

Expand Down
3 changes: 3 additions & 0 deletions astroid/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,9 @@ def _get_assign_nodes(self):

yield from self.value._get_assign_nodes()

def _get_yield_nodes_skip_lambdas(self):
yield from self.value._get_yield_nodes_skip_lambdas()


class AnnAssign(mixins.AssignTypeMixin, Statement):
"""Class representing an :class:`ast.AnnAssign` node.
Expand Down
16 changes: 16 additions & 0 deletions astroid/tests/unittest_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,5 +963,21 @@ def func2():
assert node.type_comment_returns.as_string() == expected_returns_string


def test_is_generator_for_yield_assignments():
node = astroid.extract_node('''
class A:
def test(self):
a = yield
while True:
print(a)
yield a
a = A()
a.test
''')
inferred = next(node.infer())
assert isinstance(inferred, astroid.BoundMethod)
assert bool(inferred.is_generator())


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

0 comments on commit 3f7c4bc

Please sign in to comment.