Lambdas can contain yields, do not warn about them.

Closes #123259

authorTorsten Marek <tmarek@google.com>
changeset4c4a8edd9115
branchdefault
phasepublic
hiddenno
parent revision#2748816ac5de Make sure that pragmas that apply to whole lines are interpreted literally, so that
child revision#eb226fe8265e Emit a warning for loops that have an else clause but no break or return., #962fff72742b Emit a warning for loops that have an else clause but no break or return.
files modified by this revision
ChangeLog
checkers/base.py
test/input/func_e0101.py
test/input/func_yield_outside_func.py
# HG changeset patch
# User Torsten Marek <tmarek@google.com>
# Date 1364577331 -3600
# Fri Mar 29 18:15:31 2013 +0100
# Node ID 4c4a8edd911569ecc1a3d466cd5dc033fad150c0
# Parent 2748816ac5de522bcb510f665de73425477078eb
Lambdas can contain yields, do not warn about them.

Closes #123259

diff --git a/ChangeLog b/ChangeLog
@@ -15,10 +15,12 @@
1        messages
2 
3      * #123285: apply pragmas for warnings attached to lines to
4        physical source code lines
5 
6 +    * #123259: do not emit E0105 for yield expressions inside lambdas
7 +
8      * Simplify checks for dangerous default values by unifying tests
9        for all different mutable compound literals.
10 
11      * Improve the description for E1124[redundant-keyword-arg]
12 
diff --git a/checkers/base.py b/checkers/base.py
@@ -209,11 +209,11 @@
13          if not isinstance(node.frame(), astng.Function):
14              self.add_message('E0104', node=node)
15 
16      @check_messages('E0105')
17      def visit_yield(self, node):
18 -        if not isinstance(node.frame(), astng.Function):
19 +        if not isinstance(node.frame(), (astng.Function, astng.Lambda)):
20              self.add_message('E0105', node=node)
21 
22      @check_messages('E0103')
23      def visit_continue(self, node):
24          self._check_in_loop(node, 'continue')
diff --git a/test/input/func_e0101.py b/test/input/func_e0101.py
@@ -25,5 +25,11 @@
25  class MyClass4:
26      """dummy class"""
27 
28      def __init__(self):
29          yield None
30 +
31 +class MyClass5:
32 +    """dummy class"""
33 +
34 +    def __init__(self):
35 +        self.callable = lambda: (yield None)
diff --git a/test/input/func_yield_outside_func.py b/test/input/func_yield_outside_func.py
@@ -1,4 +1,5 @@
36  """This is gramatically correct, but it's still a SyntaxError"""
37  __revision__ = None
38  yield 1
39 
40 +LAMBDA_WITH_YIELD = lambda: (yield)