diff options
author | Brett Cannon <brett@python.org> | 2014-11-14 12:36:40 -0500 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2014-11-14 12:36:40 -0500 |
commit | 277ff385e7fc63ddbb722a9ab6ceef4b56c2be4c (patch) | |
tree | 0cde2f6ccf1ead48804be4e2813a03f293e69e08 | |
parent | af213f498b2ec2fea079cef508135949b724ceaf (diff) | |
download | pylint-277ff385e7fc63ddbb722a9ab6ceef4b56c2be4c.tar.gz |
Warn when parameter unpacking is used as it is not supported in Python
3.
Part of issue #20.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | checkers/python3.py | 11 | ||||
-rw-r--r-- | test/functional/defined_and_used_on_same_line.py | 2 | ||||
-rw-r--r-- | test/unittest_checker_python3.py | 7 |
4 files changed, 22 insertions, 1 deletions
@@ -163,6 +163,9 @@ ChangeLog for Pylint * Warn when assigning to __metaclass__ at a class scope; in Python 3 a metaclass is specified as an argument to the 'class' statement. + * Warn when performing parameter tuple unpacking; it is not supported in + Python 3. + 2014-07-26 -- 1.3.0 diff --git a/checkers/python3.py b/checkers/python3.py index ca34f09..e7d056d 100644 --- a/checkers/python3.py +++ b/checkers/python3.py @@ -44,6 +44,11 @@ class Python3Checker(checkers.BaseChecker): 'Used when a print statement is used ' '(`print` is a function in Python 3)', {'maxversion': (3, 0)}), + 'E1602': ('Parameter unpacking specified', + 'parameter-unpacking', + 'Used when parameter unpacking is specified for a function' + "(Python 3 doesn't allow it)", + {'maxversion': (3, 0)}), 'W1601': ('apply built-in referenced', 'apply-builtin', 'Used when the apply built-in function is referenced ' @@ -198,6 +203,12 @@ class Python3Checker(checkers.BaseChecker): method_name = node.name[2:-2] self.add_message(method_name + '-method', node=node) + @utils.check_messages('parameter-unpacking') + def visit_arguments(self, node): + for arg in node.args: + if isinstance(arg, astroid.Tuple): + self.add_message('parameter-unpacking', node=arg) + def visit_name(self, node): """Detect when a built-in that is missing in Python 3 is referenced.""" found_node = node.lookup(node.name)[0] diff --git a/test/functional/defined_and_used_on_same_line.py b/test/functional/defined_and_used_on_same_line.py index f317ba3..fc19dc7 100644 --- a/test/functional/defined_and_used_on_same_line.py +++ b/test/functional/defined_and_used_on_same_line.py @@ -1,5 +1,5 @@ """Check for definitions and usage happening on the same line.""" -#pylint: disable=missing-docstring,multiple-statements,print-statement,no-absolute-import +#pylint: disable=missing-docstring,multiple-statements,print-statement,no-absolute-import,parameter-unpacking print [index for index in range(10)] diff --git a/test/unittest_checker_python3.py b/test/unittest_checker_python3.py index ecfbc4e..28b152d 100644 --- a/test/unittest_checker_python3.py +++ b/test/unittest_checker_python3.py @@ -244,6 +244,13 @@ class Python3CheckerTest(testutils.CheckerTestCase): with self.assertNoMessages(): self.walk(module) + @python2_only + def test_parameter_unpacking(self): + node = test_utils.extract_node('def func((a, b)):#@\n pass') + arg = node.args.args[0] + with self.assertAddsMessages(testutils.Message('parameter-unpacking', node=arg)): + self.walk(node) + if __name__ == '__main__': unittest.main() |