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 no-member (E1101) #2782

Closed
ameily opened this issue Mar 2, 2019 · 2 comments
Closed

False Positive no-member (E1101) #2782

ameily opened this issue Mar 2, 2019 · 2 comments
Labels
Duplicate 🐫 Duplicate of an already existing issue

Comments

@ameily
Copy link

ameily commented Mar 2, 2019

I'm seeing a false positive for no-member when there are two exception blocks that reuse the exception name. Here is the code block that is triggering the false positive:

def test_pylint():
    try:
        fp = open('some-file', 'r')
    except ValueError as e:
        print('error:', str(e))
        return

    try:
        fp.write(b'something')
    except OSError as e:
        print('error:', e.strerror)
    finally:
        fp.close()

The error pylint is reporting:

************* Module test_pylint
Core\test_pylint.py:13:24: E1101: Instance of 'ValueError' has no 'strerror' member (no-member)

I understand that open() may never raise a ValueError, I just used it to demonstrate the issue.

Steps to reproduce

  1. Create two separate and sequential try...except blocks that catch different exceptions. The secondtry...except must reference a member in the exception that is not available in the first exception (see above example code)
  2. Run pylint
  3. See there is a false positive for no-member on the second exception block.

Current behavior

There is a no-member error on the second exception block.

Expected behavior

pylint properly detects that the second exception block catches a different exception type and there is no no-member false positives.

pylint --version output

pylint 2.3.1
astroid 2.2.2
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]
@ameily
Copy link
Author

ameily commented Mar 2, 2019

I have confirmed that this was not an issue in pylint 2.2.2, astroid 2.0.0

@PCManticore
Copy link
Contributor

Thanks for reporting an issue. This is similar to #2777 so I'm going to close this one. What's happening is described in my comment here, basically we infer e as both OSerror and ValueError, even though e is bound in that except handler as OSError.

@PCManticore PCManticore added the Duplicate 🐫 Duplicate of an already existing issue label Mar 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

2 participants