Commits

Sylvain Thénault committed 49d0aa5 Merge

Merged in PCManticore/pylint (pull request #91)

Do not warn about returning values in generator for Python 3.3+.

Comments (0)

Files changed (6)

 
     * Add a new warning 'abstract-class-instantiated' for checking
       that abstract classes created with `abc` module and
-      with abstract methods are instantied.     
+      with abstract methods are instantied.
+
+    * Do not warn about 'return-arg-in-generator' in Python 3.3+.     
 
 2013-12-22  --  1.1.0
     * Add new check for use of deprecated pragma directives "pylint:disable-msg"
 REVERSED_METHODS = (('__getitem__', '__len__'),
                     ('__reversed__', ))
 
+PY33 = sys.version_info >= (3, 3)
 BAD_FUNCTIONS = ['map', 'filter', 'apply']
 if sys.version_info < (3, 0):
     BAD_FUNCTIONS.append('input')
               'return-arg-in-generator',
               'Used when a "return" statement with an argument is found '
               'outside in a generator function or method (e.g. with some '
-              '"yield" statements).'),
+              '"yield" statements).',
+              {'maxversion': (3, 3)}),
     'E0107': ("Use of the non-existent %s operator",
               'nonexistent-operator',
               "Used when you attempt to use the C-style pre-increment or"
                     self.add_message('return-in-init', node=node)
         elif node.is_generator():
             # make sure we don't mix non-None returns and yields
-            for retnode in returns:
-                if isinstance(retnode.value, astroid.Const) and \
-                       retnode.value.value is not None:
-                    self.add_message('return-arg-in-generator', node=node,
-                                     line=retnode.fromlineno)
+            if not PY33:
+                for retnode in returns:
+                    if isinstance(retnode.value, astroid.Const) and \
+                           retnode.value.value is not None:
+                        self.add_message('return-arg-in-generator', node=node,
+                                         line=retnode.fromlineno)
         # Check for duplicate names
         args = set()
         for name in node.argnames():

test/input/func_return_yield_mix.py

-"""pylint should detect yield and return mix inside genrators"""
-__revision__ = None
-def somegen():
-    """this is a bad generator"""
-    if True:
-        return 1
-    else:
-        yield 2
-
-def moregen():
-    """this is another bad generator"""
-    if True:
-        yield 1
-    else:
-        return 2
-

test/input/func_return_yield_mix_py_33.py

+"""pylint should detect yield and return mix inside genrators"""
+__revision__ = None
+def somegen():
+    """this is a bad generator"""
+    if True:
+        return 1
+    else:
+        yield 2
+
+def moregen():
+    """this is another bad generator"""
+    if True:
+        yield 1
+    else:
+        return 2
+

test/messages/func_return_yield_mix.txt

-E:  6:somegen: Return with argument inside generator
-E: 15:moregen: Return with argument inside generator

test/messages/func_return_yield_mix_py_33.txt

+E:  6:somegen: Return with argument inside generator
+E: 15:moregen: Return with argument inside generator