Hi,

I think I have a fix for Pylint ticket #8776, "Inline message
suppression has no effect if placed within a function's arguments
list.".

The problem is that function arguments are part of the same logical
code line as the function definition. However, messages get deleted
after they register in the arguments block, so they never touch the
logical line, defaulting to "enabled" when that line is checked.

My solution is to not delete suppression messages if the current node
is a function's arguments. This makes Pylint behave the same way
regardless if the suppression messages are placed at the beginning,
within, or at the end of the arguments list.

I edited test/input/func_w0102.py and test/messages/func_w0102.txt to
test my patch, and ran the entire Pylint test suite without any
problems.

Thanks,
Alex Margarit
diff -r f5f084e5267a ChangeLog
--- a/ChangeLog	Thu Mar 04 12:12:32 2010 +0100
+++ b/ChangeLog	Tue Mar 16 01:35:36 2010 -0400
@@ -1,6 +1,8 @@
 ChangeLog for PyLint
 ====================
  --
+    * fix #8776, inline message suppression in a function's arguments list.
+
 	* fix #9263, __init__ and __new__ are checked for unused arguments.
 
     * fix #20991, class scope definitions ignored in a genexpr
diff -r f5f084e5267a lint.py
--- a/lint.py	Thu Mar 04 12:12:32 2010 +0100
+++ b/lint.py	Tue Mar 16 01:35:36 2010 -0400
@@ -466,7 +466,10 @@
                                 self._module_msgs_state[msgid][line] = state
                             except KeyError:
                                 self._module_msgs_state[msgid] = {line: state}
-                    del lines[lineno]
+                    # the arguments list is a special case, since it is part of
+                    # the same logical code line as the function definition
+                    if str(node) != 'arguments()':
+                        del lines[lineno]
 
 
     # code checking methods ###################################################
diff -r f5f084e5267a test/input/func_w0102.py
--- a/test/input/func_w0102.py	Thu Mar 04 12:12:32 2010 +0100
+++ b/test/input/func_w0102.py	Tue Mar 16 01:35:36 2010 -0400
@@ -65,3 +65,37 @@
         """does not redefine callback returned by with_inner_function_1"""
         pass
     return callback
+
+def dangerous_default_dict_1(
+    one,
+    two,
+    three = {} 
+    ):
+    """three has a dangerous default value"""
+    return three.get(one + two)
+    
+def dangerous_default_dict_2(
+    # pylint: disable-msg=W0102
+    one,
+    two,
+    three = {} 
+    ):
+    """three has a dangerous default value - warning disabled"""
+    return three.get(one + two)
+    
+def dangerous_default_dict_3(
+    one,
+    two,
+    # pylint: disable-msg=W0102
+    three = {} 
+    ):
+    """three has a dangerous default value - warning disabled"""
+    return three.get(one + two)
+
+def dangerous_default_dict_4(
+    one,
+    two,
+    three = {} 
+    ):
+    """three has a dangerous default value"""
+    return three.get(one + two)
diff -r f5f084e5267a test/messages/func_w0102.txt
--- a/test/messages/func_w0102.txt	Thu Mar 04 12:12:32 2010 +0100
+++ b/test/messages/func_w0102.txt	Tue Mar 16 01:35:36 2010 -0400
@@ -3,3 +3,5 @@
 E: 32:func2: function already defined line 29
 E: 51:exclusive_func2: function already defined line 45
 W: 34:func2: Redefining name '__revision__' from outer scope (line 3)
+W: 69:dangerous_default_dict_1: Dangerous default value {} as argument
+W: 95:dangerous_default_dict_4: Dangerous default value {} as argument
_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to