diff options
author | Torsten Marek <tmarek@google.com> | 2013-03-29 18:15:31 +0100 |
---|---|---|
committer | Torsten Marek <tmarek@google.com> | 2013-03-29 18:15:31 +0100 |
commit | 76d17375982a1537e0bf2d2f582a312f96a3457c (patch) | |
tree | 191b99d68fa81d8f5ebe12756a90f73978c8628b | |
parent | 74f38616b403a634e879205f1550d46d909d7db9 (diff) | |
download | pylint-76d17375982a1537e0bf2d2f582a312f96a3457c.tar.gz |
Lambdas can contain yields, do not warn about them.
Closes #123259
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | checkers/base.py | 2 | ||||
-rw-r--r-- | test/input/func_e0101.py | 6 | ||||
-rw-r--r-- | test/input/func_yield_outside_func.py | 1 |
4 files changed, 10 insertions, 1 deletions
@@ -17,6 +17,8 @@ ChangeLog for PyLint * #123285: apply pragmas for warnings attached to lines to physical source code lines + * #123259: do not emit E0105 for yield expressions inside lambdas + * Simplify checks for dangerous default values by unifying tests for all different mutable compound literals. diff --git a/checkers/base.py b/checkers/base.py index ca25b76..5cc2a30 100644 --- a/checkers/base.py +++ b/checkers/base.py @@ -211,7 +211,7 @@ class BasicErrorChecker(_BasicChecker): @check_messages('E0105') def visit_yield(self, node): - if not isinstance(node.frame(), astng.Function): + if not isinstance(node.frame(), (astng.Function, astng.Lambda)): self.add_message('E0105', node=node) @check_messages('E0103') diff --git a/test/input/func_e0101.py b/test/input/func_e0101.py index a101917..0bc86e3 100644 --- a/test/input/func_e0101.py +++ b/test/input/func_e0101.py @@ -27,3 +27,9 @@ class MyClass4: def __init__(self): yield None + +class MyClass5: + """dummy class""" + + def __init__(self): + self.callable = lambda: (yield None) diff --git a/test/input/func_yield_outside_func.py b/test/input/func_yield_outside_func.py index 79d882e..c1ea3bd 100644 --- a/test/input/func_yield_outside_func.py +++ b/test/input/func_yield_outside_func.py @@ -2,3 +2,4 @@ __revision__ = None yield 1 +LAMBDA_WITH_YIELD = lambda: (yield) |