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 exception-escape #3928

Closed
r3m0t opened this issue Oct 28, 2020 · 3 comments
Closed

False positive exception-escape #3928

r3m0t opened this issue Oct 28, 2020 · 3 comments
Labels

Comments

@r3m0t
Copy link
Contributor

r3m0t commented Oct 28, 2020

Steps to reproduce


def foo():
    savedex = []
    try:
        print(1/0)
    except Exception as ex:
        savedex = [str(ex)]
    try:
        print(1/0)
    except Exception as easd:
        savedex = [str(easd)]
    print(repr([ex+'!' for ex in savedex]))
    print(easd)

Current behavior

> pylint --py3k Documents\eg.py
************* Module eg
Documents\eg.py:4:14: W1619: division w/o __future__ statement (old-division)
Documents\eg.py:11:16: W1661: Using an exception object that was bound by an except handler (exception-escape)
Documents\eg.py:8:14: W1619: division w/o __future__ statement (old-division)
Documents\eg.py:12:10: W1661: Using an exception object that was bound by an except handler (exception-escape)

Expected behavior

No exception-escape messages in output

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)]
@hippo91
Copy link
Contributor

hippo91 commented Oct 29, 2020

@r3m0t thanks for this report.
I'm unable to reproduce it. For example linting the following code:

#pylint:disable=missing-module-docstring, missing-function-docstring
#pylint:disable=blacklisted-name
def foo():
    savedex = []
    try:
        print(1/0)
    except Exception as ex:
        savedex = [str(ex)]
    try:
        print(1/0)
    except Exception as easd:
        savedex = [str(easd)]
    print(repr([ex+'!' for ex in savedex]))
    print(easd)

gives:

************* Module bug_pylint_3928
bug_pylint_3928.py:7:11: W0703: Catching too general exception Exception (broad-except)
bug_pylint_3928.py:11:11: W0703: Catching too general exception Exception (broad-except)

-------------------------------------------------------------------
Your code has been rated at 8.33/10 (previous run: 10.00/10, -1.67)

Adding the option --py3k gives no messages at all.

pylint --version
pylint 2.6.0
astroid 2.4.3
Python 3.8.2 (default, Sep 28 2020, 21:24:28) 
[GCC 8.3.0]

@PCManticore
Copy link
Contributor

I can reproduce this with the following version and with --py3k:

pylint 2.6.1-dev1
astroid 2.5.0
Python 3.6.7 (default, Feb  4 2019, 13:16:09)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]

************* Module a
a.py:4:14: W1619: division w/o __future__ statement (old-division)
a.py:11:16: W1661: Using an exception object that was bound by an except handler (exception-escape)
a.py:8:14: W1619: division w/o __future__ statement (old-division)
a.py:12:10: W1661: Using an exception object that was bound by an except handler (exception-escape)

------------------------------------------------------------------
Your code has been rated at 6.67/10 (previous run: 6.67/10, +0.00)

@Pierre-Sassoulas
Copy link
Member

Won't do, we removed the python3 porting mode in 2.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants