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 positive for E0710 and E0712 #9047

Closed
DervishD opened this issue Sep 19, 2023 · 4 comments
Closed

False positive for E0710 and E0712 #9047

DervishD opened this issue Sep 19, 2023 · 4 comments
Labels
Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning

Comments

@DervishD
Copy link

Bug description

I'm getting two false positives for errors E0710 and E0712, the first one at line 24 and the second one at line 29 of the code below.

Yes, the code is incredibly weird but the errors happened in a much bigger code I wrote and I've pruned and simplified it until the errors disappeared. The same code does not give any errors if any of the lines is removed, and that leads me to think the cause is some weird interaction of the imported code, code length, etc. Some corner case bug.

But the real problem is that I cannot reproduce this error consistently. Sometimes, in order to reproduce it, I have to close my IDE (Visual Studio Code) and relaunch. I'm reporting this here just in case other person has the same problem with a more consistent way of reproducing the problem, so there's at least something appearing on searches.

Thanks a lot in advance, and feel free to ask me for any additional information needed.

#! /usr/bin/env python3
# pylint: disable=C0114 C0115 C0116 R0903 W0612
import re

class SampleError(Exception):
    pass

class SampleClass():
    pass

def func1():
    var1 = None
    if var1:
        if var1:
            var1 = re.search('', '')
            if var1:
                var1 = None

def func2():
    for var1 in SampleClass.__subclasses__():
        pass

def func3():
    raise SampleError

def main():
    try:
        func3()
    except SampleError:
        pass

main()

Configuration

No response

Command used

python.exe -m pylint --reports=n --output-format=json --clear-cache-post-run=y --from-stdin t.py

Pylint output

python.exe -m pylint --reports=n --output-format=json --clear-cache-post-run=y --from-stdin t.py
file:t.py :
[
    {
        "type": "error",
        "module": "t",
        "obj": "func3",
        "line": 24,
        "column": 4,
        "endLine": 24,
        "endColumn": 21,
        "path": "t.py",
        "symbol": "raising-non-exception",
        "message": "Raising a new style class which doesn't inherit from BaseException",
        "message-id": "E0710"
    },
    {
        "type": "error",
        "module": "t",
        "obj": "main",
        "line": 29,
        "column": 11,
        "endLine": 29,
        "endColumn": 22,
        "path": "t.py",
        "symbol": "catching-non-exception",
        "message": "Catching an exception which doesn't inherit from Exception: SampleError",
        "message-id": "E0712"
    }
]

Expected behavior

No errors since the code is perfectly valid and in fact the new exception inherits from Exception.

Pylint version

pylint 2.17.4
astroid 2.15.5
Python 3.11.4 (tags/v3.11.4:d2340ef, Jun  7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)]

OS / Environment

Windows 10 Home 64 bit, embedded Pylint for Visual Studio Code 1.82.2

Additional dependencies

No response

@DervishD DervishD added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 19, 2023
@mbyrnepr2
Copy link
Member

This isn't something I can reproduce as-is. Perhaps a pylint configuration in a file such as .pylintrc, pyproject.toml, setup.py or tox.ini is affecting the outcome for you.

@mbyrnepr2 mbyrnepr2 added Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 19, 2023
@DervishD
Copy link
Author

I made sure to disable my personal pylintrc, and the project does not have one, but maybe the Visual Studio Code embedded pylint has some kind of internal configuration. Not that I know, but I can't be sure.

I've switched from the embedded pylint to a locally installed version to try to reproduce the issue consistently, but so far I've failed to achieve it.

I'll keep testing and trying to find a consistent reproducible scenario, but I'm starting to think that the problem is in the embedded version of Visual Studio Code, or maybe the extension itself, rather than pylint.

I'll post here any news. Thanks for your reply.

@DervishD
Copy link
Author

The problem definitely lies within Visual Studio Code: the errors disappear if I restart the pylint server by hand, and they happen with a locally installed version of pylint.

I suspect that the linting server is not getting the entire code in one go, and sometimes is getting only part of it, missing the points where the custom errors are declared and derive from Exception, and that causes the error. It also explains why the minimal code I included is so weird: it has to trigger that condition and maybe length, complexity and whatnot is what triggers the bug.

I'll report in Visual Studio Code or in the pylint extension if I can reproduce the problem more reliably.

Meanwhile I'm closing this bug since it does not seem to be caused by pylint itself.

Thanks a lot and sorry for the noise 😉

@mbyrnepr2
Copy link
Member

Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning
Projects
None yet
Development

No branches or pull requests

2 participants