Open daviderie opened 2 months ago
Thank you for opening the issue. We have some mechanisms so that name with underscore are ignored, they should probably not be ignored for function-redefined
though, there's no good reasons to ignore that one imo.
basic_error_checker.py
has:
dummy_variables_rgx = self.linter.config.dummy_variables_rgx
if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
return
self.add_message(
"function-redefined",
node=node,
args=(redeftype, defined_self.fromlineno),
)
Test case:
def dummy_func():
"""First dummy function"""
pass
def dummy_func():
"""Second dummy function, don't emit function-redefined message
because of the dummy name"""
pass
I guess the idea is to skip this check for certain names? But I don't know why that would be desirable.
It's useful when you want to ignore that a variable is not used for example, for for _ in range(3):
or in a function definition for an API you can't change (without a pylint: disable). It's been extended too much here, function-redefined
has no reason to be disabled with a shorthand (I don't see why it would ever be disabled with a pragma either?). The semantic between variable and function prefixed by _
is very different (protected function vs known unused variable) and are not interchangeable.
Bug description
When defining a function that is named with a leading underscore, Pylint does not raise the function-redefined error as expected.
E.g.:
Configuration
defaults
Command used
Pylint output
Expected behavior
E0102: method already defined line 86 (function-redefined)
Pylint version
OS / Environment
No response
Additional dependencies
No response