File tree Expand file tree Collapse file tree 4 files changed +22
-1
lines changed Expand file tree Collapse file tree 4 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ What's New in astroid 2.4.2?
6
6
============================
7
7
Release Date: TBA
8
8
9
+ * `FunctionDef.is_generator` properly handles `yield` nodes in `While` tests
10
+
11
+ Close PyCQA/pylint#3519
12
+
9
13
10
14
What's New in astroid 2.4.1?
11
15
============================
Original file line number Diff line number Diff line change @@ -4500,6 +4500,11 @@ def get_children(self):
4500
4500
yield from self .body
4501
4501
yield from self .orelse
4502
4502
4503
+ def _get_yield_nodes_skip_lambdas (self ):
4504
+ """A While node can contain a Yield node in the test"""
4505
+ yield from self .test ._get_yield_nodes_skip_lambdas ()
4506
+ yield from super ()._get_yield_nodes_skip_lambdas ()
4507
+
4503
4508
4504
4509
class With (
4505
4510
mixins .MultiLineBlockMixin ,
Original file line number Diff line number Diff line change @@ -1661,7 +1661,7 @@ def is_generator(self):
1661
1661
:returns: True is this is a generator function, False otherwise.
1662
1662
:rtype: bool
1663
1663
"""
1664
- return next (self ._get_yield_nodes_skip_lambdas (), False )
1664
+ return bool ( next (self ._get_yield_nodes_skip_lambdas (), False ) )
1665
1665
1666
1666
def infer_call_result (self , caller = None , context = None ):
1667
1667
"""Infer what the function returns when called.
Original file line number Diff line number Diff line change @@ -1335,5 +1335,17 @@ def test_const_itered():
1335
1335
assert [elem .value for elem in itered ] == list ("string" )
1336
1336
1337
1337
1338
+ def test_is_generator_for_yield_in_while ():
1339
+ code = """
1340
+ def paused_iter(iterable):
1341
+ while True:
1342
+ # Continue to yield the same item until `next(i)` or `i.send(False)`
1343
+ while (yield value):
1344
+ pass
1345
+ """
1346
+ node = astroid .extract_node (code )
1347
+ assert bool (node .is_generator ())
1348
+
1349
+
1338
1350
if __name__ == "__main__" :
1339
1351
unittest .main ()
You can’t perform that action at this time.
0 commit comments