diff options
| author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-04-18 13:00:27 +0300 |
|---|---|---|
| committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-04-18 13:00:27 +0300 |
| commit | 3edc3dccffae9e97550e398096a18f8a60e5dd77 (patch) | |
| tree | 627243e90c47925f7126ec028769e86d0a6fbacb | |
| parent | 2dfd78afb995f6275815658b81c13876ad5423bf (diff) | |
| download | pylint-3edc3dccffae9e97550e398096a18f8a60e5dd77.tar.gz | |
Provide some hints for the bad-builtin message. Closes issue #522.
| -rw-r--r-- | ChangeLog | 2 | ||||
| -rw-r--r-- | pylint/checkers/base.py | 15 | ||||
| -rw-r--r-- | pylint/test/functional/bad_builtin.py | 1 | ||||
| -rw-r--r-- | pylint/test/functional/bad_builtin.txt | 3 | ||||
| -rw-r--r-- | pylint/test/messages/func_3k_removed_stuff_py_30.txt | 4 |
5 files changed, 20 insertions, 5 deletions
@@ -55,6 +55,8 @@ ChangeLog for Pylint * Don't emit redefined-outer-name for __future__ directives. Closes issue #520. + * Provide some hints for the bad-builtin message. Closes issue #522. + 2015-03-14 -- 1.4.3 diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index d50369c..532ad01 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -69,6 +69,12 @@ BAD_FUNCTIONS = ['map', 'filter'] if sys.version_info < (3, 0): BAD_FUNCTIONS.append('input') +# Some hints regarding the use of bad builtins. +BUILTIN_HINTS = { + 'map': 'Using a list comprehension can be clearer.', +} +BUILTIN_HINTS['filter'] = BUILTIN_HINTS['map'] + # Name categories that are always consistent with all naming conventions. EXEMPT_NAME_CATEGORIES = set(('exempt', 'ignore')) @@ -493,7 +499,7 @@ functions, methods 'usage. Consider using `ast.literal_eval` for safely evaluating ' 'strings containing Python expressions ' 'from untrusted sources. '), - 'W0141': ('Used builtin function %r', + 'W0141': ('Used builtin function %s', 'bad-builtin', 'Used when a black listed builtin function is used (see the ' 'bad-function option). Usual black listed functions are the ones ' @@ -777,7 +783,12 @@ functions, methods elif name == 'eval': self.add_message('eval-used', node=node) if name in self.config.bad_functions: - self.add_message('bad-builtin', node=node, args=name) + hint = BUILTIN_HINTS.get(name) + if hint: + args = "%r. %s" % (name, hint) + else: + args = repr(name) + self.add_message('bad-builtin', node=node, args=args) @check_messages('assert-on-tuple') def visit_assert(self, node): diff --git a/pylint/test/functional/bad_builtin.py b/pylint/test/functional/bad_builtin.py index fd4eaf6..1ca9790 100644 --- a/pylint/test/functional/bad_builtin.py +++ b/pylint/test/functional/bad_builtin.py @@ -1,3 +1,4 @@ # pylint: disable=missing-docstring
TEST = map(str, (1, 2, 3)) # [bad-builtin]
+TEST1 = filter(str, (1, 2, 3)) # [bad-builtin]
diff --git a/pylint/test/functional/bad_builtin.txt b/pylint/test/functional/bad_builtin.txt index 8a3d610..552f196 100644 --- a/pylint/test/functional/bad_builtin.txt +++ b/pylint/test/functional/bad_builtin.txt @@ -1 +1,2 @@ -bad-builtin:3::Used builtin function 'map' +bad-builtin:3::Used builtin function 'map'. Using a list comprehension can be clearer. +bad-builtin:4::Used builtin function 'filter'. Using a list comprehension can be clearer. diff --git a/pylint/test/messages/func_3k_removed_stuff_py_30.txt b/pylint/test/messages/func_3k_removed_stuff_py_30.txt index e7ede06..a8e462e 100644 --- a/pylint/test/messages/func_3k_removed_stuff_py_30.txt +++ b/pylint/test/messages/func_3k_removed_stuff_py_30.txt @@ -1,5 +1,5 @@ E: 12:function: Instance of 'unicode' has no 'looower' member -W: 3: Used builtin function 'filter' -W: 3: Used builtin function 'map' +W: 3: Used builtin function 'filter'. Using a list comprehension can be clearer. +W: 3: Used builtin function 'map'. Using a list comprehension can be clearer. W: 4: __future__ import is not the first non docstring statement W: 6: Relative import 'func_w0302', should be 'input.func_w0302' |
