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: Wrong number of arguments for isinstance #9847

Closed
nickdrozd opened this issue Aug 2, 2024 · 3 comments · Fixed by #9868 or #9940
Closed

False negative: Wrong number of arguments for isinstance #9847

nickdrozd opened this issue Aug 2, 2024 · 3 comments · Fixed by #9868 or #9940
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Good first issue Friendly and approachable by new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@nickdrozd
Copy link
Contributor

Bug description

isinstance(5)
isinstance(5, int, int)

Configuration

No response

Command used

pylint

Pylint output

No warnings

Expected behavior

Pylint should warn that the number of arguments is wrong.

I don't know if this affects other builtin functions.

Pylint version

pylint 3.2.6
astroid 3.2.4
Python 3.11.1 (main, Dec  7 2022, 01:11:44) [GCC 9.4.0]

OS / Environment

No response

Additional dependencies

No response

@nickdrozd nickdrozd added Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling 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 2, 2024
@jacobtylerwalls jacobtylerwalls added the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label Aug 4, 2024
@rogersheu
Copy link
Contributor

rogersheu commented Aug 11, 2024

The following comment seems to suggest that addressing this will be difficult.

# Built-in functions have no argument information.

I tested a number of other built-in functions (hasattr, getattr, bool, int, etc.) and all of them get skipped.

@nickdrozd
Copy link
Contributor Author

@rogersheu Fixing it for all builtins might be difficult, but fixing it just for isinstance looks easy:

    def _check_isinstance_args(self, node: nodes.Call) -> None:
        if len(node.args) != 2:
            # isinstance called with wrong number of args
            return

Instead of returning, raise the appropriate error instead.

@rogersheu
Copy link
Contributor

rogersheu commented Aug 11, 2024

Thanks for pointing that out @nickdrozd! I've opened a PR to address this 👌.

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 Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
3 participants