diff options
author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-04-16 13:40:00 +0300 |
---|---|---|
committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2015-04-16 13:40:00 +0300 |
commit | 3aeab3a1de09763cc749bc239d71cf6b81616530 (patch) | |
tree | b6fbc5e5c5b07f1f1fce05ed01acf2c454a08265 | |
parent | 0c1818005e9b07b304a7c5933abc58e7b81f9078 (diff) | |
download | pylint-3aeab3a1de09763cc749bc239d71cf6b81616530.tar.gz |
Don't emit redefined-outer-name for __future__ directives.
Closes issue #520.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | pylint/checkers/variables.py | 15 | ||||
-rw-r--r-- | pylint/test/functional/function_redefined.py | 11 |
3 files changed, 23 insertions, 6 deletions
@@ -52,6 +52,9 @@ ChangeLog for Pylint * Don't emit missing-docstring for private functions. + * Don't emit redefined-outer-name for __future__ directives. + Closes issue #520. + 2015-03-14 -- 1.4.3 diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index c813727..f4fc853 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -35,7 +35,7 @@ from pylint.checkers.utils import ( import six SPECIAL_OBJ = re.compile("^_{2}[a-z]+_{2}$") - +FUTURE = '__future__' PY3K = sys.version_info >= (3, 0) @@ -516,10 +516,17 @@ builtins. Remember that you should avoid to define new builtins when possible.' if is_inside_except(stmt): continue if name in globs and not isinstance(stmt, astroid.Global): - line = globs[name][0].fromlineno + definition = globs[name][0] + if (isinstance(definition, astroid.From) + and definition.modname == FUTURE): + # It is a __future__ directive, not a symbol. + continue + + line = definition.fromlineno dummy_rgx = self.config.dummy_variables_rgx - if not dummy_rgx.match(name): - self.add_message('redefined-outer-name', args=(name, line), node=stmt) + if not dummy_rgx.match(name): + self.add_message('redefined-outer-name', + args=(name, line), node=stmt) elif is_builtin(name): # do not print Redefining builtin for additional builtins self.add_message('redefined-builtin', args=name, node=stmt) diff --git a/pylint/test/functional/function_redefined.py b/pylint/test/functional/function_redefined.py index 412ff28..30835a5 100644 --- a/pylint/test/functional/function_redefined.py +++ b/pylint/test/functional/function_redefined.py @@ -1,5 +1,5 @@ -# pylint: disable=R0201 -"""docstring""" +# pylint: disable=R0201,missing-docstring +from __future__ import division __revision__ = '' class AAAA(object): @@ -65,3 +65,10 @@ def with_inner_function_2(): """does not redefine callback returned by with_inner_function_1""" pass return callback + +def some_func(): + """Don't emit if we defined a variable with the same name as a + __future__ directive. + """ + division = 2 + return division |