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 attribute resolution of function's argument #4242

Closed
stanislavlevin opened this issue Mar 17, 2021 · 4 comments
Closed

False negative attribute resolution of function's argument #4242

stanislavlevin opened this issue Mar 17, 2021 · 4 comments
Labels
Bug 🪲 Control flow Requires control flow understanding Duplicate 🐫 Duplicate of an already existing issue False Negative 🦋 No message is emitted but something is wrong with the code

Comments

@stanislavlevin
Copy link
Contributor

Steps to reproduce

Given a file a.py:

def test(val):
    val.somethingwrong()

test(1)

Current behavior

Result of pylint a.py:

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

Expected behavior

Pylint should report an error.

pylint --version output

Result of pylint --version output:

pylint 2.7.2
astroid 2.5.1
Python 3.9.2 (default, Feb 26 2021, 15:33:46) 
[GCC 10.2.1 20201125 (ALT Sisyphus 10.2.1-alt2)]
@hippo91
Copy link
Contributor

hippo91 commented Apr 9, 2021

@stanislavlevin thanks for your report. I don't think it is a pylint bug. The only way to detect an error would be to detect that test parameter is 1 and so doesn't have somethingwrong method. However doing this would necessitate that astroid, the pylint's inference engine has control-flow analysis ability. This is not yet the case and it is really a huge work.

@hippo91 hippo91 added Bug 🪲 False Negative 🦋 No message is emitted but something is wrong with the code Control flow Requires control flow understanding labels Apr 9, 2021
@Pierre-Sassoulas
Copy link
Member

mypy does not find this either and typing is its specialty. I think it's safe to say you need to at least add typing if you want proper reporting.

Ie:

class MyClass:
    def somethingwrong(self):
        pass

def test(val:MyClass):
    val.somethingwrong()

test(1)

mypy:

a.py:9: error: Argument 1 to "test" has incompatible type "int"; expected "MyClass"

@stanislavlevin
Copy link
Contributor Author

I've already realized that it is mypy task and without annotations it is unsolvable at all. So if there are no plans to add support for type hints in Pylint then please close this issue.

@Pierre-Sassoulas
Copy link
Member

Closing as a duplicate of #4813

@Pierre-Sassoulas Pierre-Sassoulas closed this as not planned Won't fix, can't repro, duplicate, stale Jul 2, 2022
@Pierre-Sassoulas Pierre-Sassoulas added the Duplicate 🐫 Duplicate of an already existing issue label Jul 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Control flow Requires control flow understanding Duplicate 🐫 Duplicate of an already existing issue False Negative 🦋 No message is emitted but something is wrong with the code
Projects
None yet
Development

No branches or pull requests

3 participants