From ef2209b2a9846fbd3878474eeac91a8fc55751bc Mon Sep 17 00:00:00 2001 From: cpopa Date: Sat, 27 Jul 2013 15:50:49 +0300 Subject: Check for builtin exec function for Python 3. --- checkers/base.py | 10 ++++++++-- test/input/func_exec_function_py30.py | 13 +++++++++++++ test/messages/func_exec_function_py30.txt | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/input/func_exec_function_py30.py create mode 100644 test/messages/func_exec_function_py30.txt diff --git a/checkers/base.py b/checkers/base.py index 4b3b3c9..ff472ec 100644 --- a/checkers/base.py +++ b/checkers/base.py @@ -379,7 +379,11 @@ functions, methods 'Used when you use the "exec" statement, to discourage its \ usage. That doesn\'t mean you can not use it !', {'maxversion': (3, 0)}), - + 'W0123': ('Use of the exec function', + 'exec-function', + 'Used when you use the "exec" function, to discourage its \ + usage. That doesn\'t mean you can not use it !', + {'minversion': (3, 0)}), 'W0141': ('Used builtin function %r', 'bad-builtin', 'Used when a black listed builtin function is used (see the ' @@ -600,7 +604,7 @@ functions, methods """just print a warning on exec statements""" self.add_message('exec-statement', node=node) - @check_messages('bad-builtin', 'star-args') + @check_messages('bad-builtin', 'star-args', 'exec-function') 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 +615,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-function', 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_function_py30.py b/test/input/func_exec_function_py30.py new file mode 100644 index 0000000..dbcc024 --- /dev/null +++ b/test/input/func_exec_function_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_function_py30.txt b/test/messages/func_exec_function_py30.txt new file mode 100644 index 0000000..a867b82 --- /dev/null +++ b/test/messages/func_exec_function_py30.txt @@ -0,0 +1,4 @@ +W: 5: Use of the exec function +W: 6: Use of the exec function +W: 8: Use of the exec function +W: 12:func: Use of the exec function -- cgit v1.2.1 From e7df34f29b5c611005fd69e60c090d5cda316b3c Mon Sep 17 00:00:00 2001 From: cpopa Date: Sat, 27 Jul 2013 15:54:03 +0300 Subject: Update changelog. --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3bfb10d..3a35f95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ ChangeLog for Pylint ==================== -- + * Add check for the use of 'exec' function + * Do not emit [fixme] for every line if the config value 'notes' is empty, but [fixme] is enabled. -- cgit v1.2.1 From eab32695c40e3435def1465cb2aa5d39ce32ba09 Mon Sep 17 00:00:00 2001 From: cpopa Date: Thu, 1 Aug 2013 16:19:49 +0300 Subject: Combine exec-function with exec-statement, rename test files. --- checkers/base.py | 20 +++++++------------- test/input/func_exec_function_py30.py | 13 ------------- test/input/func_exec_used_py30.py | 13 +++++++++++++ test/messages/func_exec_function_py30.txt | 4 ---- test/messages/func_exec_used_py30.txt | 4 ++++ test/messages/func_w0122_py_30.txt | 8 ++++---- 6 files changed, 28 insertions(+), 34 deletions(-) delete mode 100644 test/input/func_exec_function_py30.py create mode 100644 test/input/func_exec_used_py30.py delete mode 100644 test/messages/func_exec_function_py30.txt create mode 100644 test/messages/func_exec_used_py30.txt diff --git a/checkers/base.py b/checkers/base.py index ff472ec..ac58114 100644 --- a/checkers/base.py +++ b/checkers/base.py @@ -374,16 +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', + 'W0122': ('Use of exec', + 'exec-used', 'Used when you use the "exec" statement, to discourage its \ - usage. That doesn\'t mean you can not use it !', - {'maxversion': (3, 0)}), - 'W0123': ('Use of the exec function', - 'exec-function', - 'Used when you use the "exec" function, to discourage its \ - usage. That doesn\'t mean you can not use it !', - {'minversion': (3, 0)}), + 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 ' @@ -599,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', 'exec-function') + @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 @@ -616,7 +610,7 @@ functions, methods if not (name in node.frame() or name in node.root()): if name == 'exec': - self.add_message('exec-function', node=node) + 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_function_py30.py b/test/input/func_exec_function_py30.py deleted file mode 100644 index dbcc024..0000000 --- a/test/input/func_exec_function_py30.py +++ /dev/null @@ -1,13 +0,0 @@ -"""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/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_function_py30.txt b/test/messages/func_exec_function_py30.txt deleted file mode 100644 index a867b82..0000000 --- a/test/messages/func_exec_function_py30.txt +++ /dev/null @@ -1,4 +0,0 @@ -W: 5: Use of the exec function -W: 6: Use of the exec function -W: 8: Use of the exec function -W: 12:func: Use of the exec function 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 -- cgit v1.2.1 From d0f09414200182eb4202d78af9e1e37314a36843 Mon Sep 17 00:00:00 2001 From: cpopa Date: Fri, 2 Aug 2013 12:24:00 +0300 Subject: Update changelog and description message. --- ChangeLog | 4 ++++ checkers/base.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3a35f95..4a877a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,10 @@ 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 + * Do not emit [fixme] for every line if the config value 'notes' is empty, but [fixme] is enabled. diff --git a/checkers/base.py b/checkers/base.py index ac58114..014bfc4 100644 --- a/checkers/base.py +++ b/checkers/base.py @@ -376,7 +376,7 @@ functions, methods times."), 'W0122': ('Use of exec', 'exec-used', - 'Used when you use the "exec" statement, to discourage its \ + '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', -- cgit v1.2.1 From 1f5d694f0af58af8c5a6032dc4d57b08653500d5 Mon Sep 17 00:00:00 2001 From: cpopa Date: Fri, 2 Aug 2013 12:26:46 +0300 Subject: Proper conflict fix. --- ChangeLog | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a877a9..dd03e52 100644 --- a/ChangeLog +++ b/ChangeLog @@ -79,7 +79,7 @@ ChangeLog for Pylint * Added a new warning 'old-raise-syntax' for the deprecated syntax raise Exception, args - * Support for PEP 3102 and new missing-kwoa (E1125) message for missing + * Support for PEP 3102 and new missing-kwoa (E1125) message for missing mandatory keyword argument (logilab.org's #107788) * Fix spelling of max-branchs option, now max-branches @@ -96,12 +96,14 @@ ChangeLog for Pylint containers like tuple * bitbucket #16: fix False positive E1003 on Python 3 for argument-less super() - + * bitbucket #6: put back documentation in source distribution * bitbucket #15: epylint shouldn't hang anymore when there is a large output on pylint'stderr + * bitbucket #7: fix epylint w/ python3 + * bitbucket #3: remove string module from the default list of deprecated modules -- cgit v1.2.1