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

False Negative function-redefined when function named with leading underscore #9894

Open
daviderie opened this issue Aug 26, 2024 · 3 comments
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors

Comments

@daviderie
Copy link

daviderie commented Aug 26, 2024

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.:

def _my_func(self):
    ...

def _my_func(self):
    ...

Configuration

defaults

Command used

pylint my_package

Pylint output

-------------------------------------------------------------------
Your code has been rated at 10.00/10

Expected behavior

E0102: method already defined line 86 (function-redefined)

Pylint version

pylint 3.2.6
astroid 3.2.4
Python 3.11.3 (main, May  4 2023, 15:16:43) [Clang 14.0.3 (clang-1403.0.22.14.1)]

OS / Environment

No response

Additional dependencies

No response

@daviderie daviderie added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Aug 26, 2024
@Pierre-Sassoulas Pierre-Sassoulas added Help wanted 🙏 Outside help would be appreciated, good for new contributors Good first issue Friendly and approachable by new contributors False Negative 🦋 No message is emitted but something is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 27, 2024
@Pierre-Sassoulas
Copy link
Member

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.

@nickdrozd
Copy link
Collaborator

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.

@Pierre-Sassoulas
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors
Projects
None yet
Development

No branches or pull requests

10 participants
@Pierre-Sassoulas @nickdrozd @daviderie and others