summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-12-14 11:11:00 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2018-12-14 11:11:26 +0100
commit2e2879379441514ef7a15d7e4169f545574ce00a (patch)
treee0d45dcab9a7ac7bed5550f193b09179d1ec43c2
parent735618916c63ba2f8b647fbd45dcf2456343836c (diff)
downloadpylint-git-2e2879379441514ef7a15d7e4169f545574ce00a.tar.gz
Exempt ``yield from`` from ``*-not-iterating`` Python 3 checks.
Close #2643
-rw-r--r--ChangeLog4
-rw-r--r--pylint/checkers/python3.py3
-rw-r--r--pylint/test/unittest_checker_python3.py7
3 files changed, 14 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 22726dceb..8a3779b87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,10 @@ Release date: TBA
Close #2558
+* Exempt ``yield from`` from ``*-not-iterating`` Python 3 checks.
+
+ Close #2643
+
* Fix incorrect generation of ``no-else-return`` warnings (R1705)
Fixed issue where ``if`` statements with nested ``if`` statements
diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py
index 572e22024..f76bb0050 100644
--- a/pylint/checkers/python3.py
+++ b/pylint/checkers/python3.py
@@ -143,6 +143,9 @@ def _in_iterating_context(node):
and parent.ops[0][0] == "in"
):
return True
+ # Also if it's an `yield from`, that's fair
+ elif isinstance(parent, astroid.YieldFrom):
+ return True
return False
diff --git a/pylint/test/unittest_checker_python3.py b/pylint/test/unittest_checker_python3.py
index fc727bf3c..3b0ebcb33 100644
--- a/pylint/test/unittest_checker_python3.py
+++ b/pylint/test/unittest_checker_python3.py
@@ -103,6 +103,12 @@ class TestPython3Checker(testutils.CheckerTestCase):
with self.assertNoMessages():
self.walk(module)
+ def as_iterable_in_yield_from(self, fxn):
+ code = "yield from {}()".format(fxn)
+ module = astroid.parse(code)
+ with self.assertNoMessages():
+ self.walk(module)
+
def as_used_in_variant_in_genexp_test(self, fxn):
checker = "{}-builtin-not-iterating".format(fxn)
node = astroid.extract_node(
@@ -202,6 +208,7 @@ class TestPython3Checker(testutils.CheckerTestCase):
self.as_iterable_in_unpacking(fxn)
self.as_assignment(fxn)
self.as_argument_to_materialized_filter(fxn)
+ self.as_iterable_in_yield_from(fxn)
for func in (
"iter",