Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false positive for function-redefined for simple type annotations #4938

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -39,6 +39,10 @@ Release date: TBA

Closes #3802

* Fix false positive for ``function-redefined`` for simple type annotations

Closes #4936


What's New in Pylint 2.10.3?
============================
Expand Down
4 changes: 4 additions & 0 deletions doc/whatsnew/2.11.rst
Expand Up @@ -41,3 +41,7 @@ Other Changes
* Added ``py-version`` config key (if ``[MASTER]`` section). Used for version dependant checks.
Will default to whatever Python version pylint is executed with.
* The ``invalid-name`` message is now more detailed when using multiple naming style regexes.

* Fix false positive for ``function-redefined`` for simple type annotations

Closes #4936
6 changes: 5 additions & 1 deletion pylint/checkers/base.py
Expand Up @@ -862,7 +862,11 @@ def _check_redefinition(self, redeftype, node):
parent_frame = node.parent.frame()

# Ignore function stubs created for type information
redefinitions = parent_frame.locals[node.name]
redefinitions = [
i
for i in parent_frame.locals[node.name]
if not (isinstance(i.parent, nodes.AnnAssign) and i.parent.simple)
]
defined_self = next(
(local for local in redefinitions if not utils.is_overload_stub(local)),
node,
Expand Down
8 changes: 8 additions & 0 deletions tests/functional/f/function_redefined.py
@@ -1,6 +1,9 @@
# pylint: disable=no-self-use,missing-docstring,using-constant-test, useless-object-inheritance
# pylint: disable=unused-import,wrong-import-position,reimported, unnecessary-pass
from __future__ import division

from typing import Callable

__revision__ = ''
class AAAA(object):
"""docstring"""
Expand Down Expand Up @@ -118,3 +121,8 @@ def callback1():
def callback2():
return 24
return callback1(), callback2()

do_something: Callable[[], int]

def do_something() -> int:
return 1
14 changes: 7 additions & 7 deletions tests/functional/f/function_redefined.txt
@@ -1,7 +1,7 @@
function-redefined:15:4:AAAA.method2:method already defined line 12
function-redefined:18:0:AAAA:class already defined line 5
function-redefined:32:0:func2:function already defined line 29
redefined-outer-name:34:4:func2:Redefining name '__revision__' from outer scope (line 4)
function-redefined:51:4:exclusive_func2:function already defined line 45
function-redefined:86:0:ceil:function already defined line 85
function-redefined:90:0:math:function already defined line 89
function-redefined:18:4:AAAA.method2:method already defined line 15:HIGH
function-redefined:21:0:AAAA:class already defined line 8:HIGH
function-redefined:35:0:func2:function already defined line 32:HIGH
redefined-outer-name:37:4:func2:Redefining name '__revision__' from outer scope (line 7):HIGH
function-redefined:54:4:exclusive_func2:function already defined line 48:HIGH
function-redefined:89:0:ceil:function already defined line 88:HIGH
function-redefined:93:0:math:function already defined line 92:HIGH