summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcpopa <devnull@localhost>2013-08-02 12:32:47 +0300
committercpopa <devnull@localhost>2013-08-02 12:32:47 +0300
commit223ecc8e017662c60b6e5fed1f7cec4893a89cd3 (patch)
tree19496cc08884dc625a1fb806fb91b3fe0c7caa8a
parentf1b0ea4a88aeaa100865a056f9321c9646565bb9 (diff)
parent1f5d694f0af58af8c5a6032dc4d57b08653500d5 (diff)
downloadpylint-exec.tar.gz
merge with Pylint defaultexec
-rw-r--r--ChangeLog2
-rw-r--r--checkers/base.py18
-rw-r--r--test/input/func_exec_used_py30.py13
-rw-r--r--test/messages/func_exec_used_py30.txt4
-rw-r--r--test/messages/func_w0122_py_30.txt8
5 files changed, 32 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 0b947f7..dd03e52 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@ ChangeLog for Pylint
====================
--
+ * Add check for the use of 'exec' function
+
* New --msg-template option to control output, deprecating "msvc" and
"parseable" output formats as well as killing `--include-ids` and `--symbols`
options
diff --git a/checkers/base.py b/checkers/base.py
index bb6f778..de40c4c 100644
--- a/checkers/base.py
+++ b/checkers/base.py
@@ -374,12 +374,10 @@ functions, methods
'duplicate-key',
"Used when a dictionary expression binds the same key multiple \
times."),
- 'W0122': ('Use of the exec statement',
- 'exec-statement',
- 'Used when you use the "exec" statement, to discourage its \
- usage. That doesn\'t mean you can not use it !',
- {'maxversion': (3, 0)}),
-
+ 'W0122': ('Use of exec',
+ 'exec-used',
+ 'Used when you use the "exec" statement (function for Python 3), to discourage its \
+ usage. That doesn\'t mean you can not use it !'),
'W0141': ('Used builtin function %r',
'bad-builtin',
'Used when a black listed builtin function is used (see the '
@@ -595,12 +593,12 @@ functions, methods
if node.exc is not None and node.inst is not None and node.tback is None:
self.add_message('old-raise-syntax', node=node)
- @check_messages('exec-statement')
+ @check_messages('exec-used')
def visit_exec(self, node):
"""just print a warning on exec statements"""
- self.add_message('exec-statement', node=node)
+ self.add_message('exec-used', node=node)
- @check_messages('bad-builtin', 'star-args')
+ @check_messages('bad-builtin', 'star-args', 'exec-used')
def visit_callfunc(self, node):
"""visit a CallFunc node -> check if this is not a blacklisted builtin
call and check for * or ** use
@@ -611,6 +609,8 @@ functions, methods
# locals nor globals scope)
if not (name in node.frame() or
name in node.root()):
+ if name == 'exec':
+ self.add_message('exec-used', node=node)
if name in self.config.bad_functions:
self.add_message('bad-builtin', node=node, args=name)
if node.starargs or node.kwargs:
diff --git a/test/input/func_exec_used_py30.py b/test/input/func_exec_used_py30.py
new file mode 100644
index 0000000..dbcc024
--- /dev/null
+++ b/test/input/func_exec_used_py30.py
@@ -0,0 +1,13 @@
+"""test global statement"""
+
+__revision__ = 0
+
+exec('a = __revision__')
+exec('a = 1', globals={})
+
+exec('a = 1', globals=globals())
+
+def func():
+ """exec in local scope"""
+ exec('b = 1')
+
diff --git a/test/messages/func_exec_used_py30.txt b/test/messages/func_exec_used_py30.txt
new file mode 100644
index 0000000..362da68
--- /dev/null
+++ b/test/messages/func_exec_used_py30.txt
@@ -0,0 +1,4 @@
+W: 5: Use of exec
+W: 6: Use of exec
+W: 8: Use of exec
+W: 12:func: Use of exec
diff --git a/test/messages/func_w0122_py_30.txt b/test/messages/func_w0122_py_30.txt
index 1522cac..d833076 100644
--- a/test/messages/func_w0122_py_30.txt
+++ b/test/messages/func_w0122_py_30.txt
@@ -1,5 +1,5 @@
-W: 5: Use of the exec statement
-W: 6: Use of the exec statement
-W: 8: Use of the exec statement
-W: 12:func: Use of the exec statement
+W: 5: Use of exec
+W: 6: Use of exec
+W: 8: Use of exec
+W: 12:func: Use of exec