Skip to content

False positive for E0710 and E0712 #9047

Closed
@DervishD

Description

@DervishD

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs investigation 🔬A bug or crash where it's not immediately obvious what is happenning

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions