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 error report E1101 with EnvironmentError #2777

Labels

Comments

@plocharz-9livesdata
Copy link

plocharz-9livesdata commented Feb 28, 2019

test-pylint.py

import os
import psutil

try:
    os.stat("does not exist")
except psutil.Error as e:
    pass

try:
    os.stat("does not exist")
except EnvironmentError as e:
    err = e.strerror

Steps to reproduce

  1. run pylint -E test-pylint.py

Current behavior

************* Module test-pylint
test-pylint.py:12:10: E1101: Instance of 'Error' has no 'strerror' member (no-member)

Expected behavior

No output is expected

Workaround:

Use different names for error variables:

import os
import psutil

try:
    os.stat("does not exist")
except psutil.Error as e:
    pass

try:
    os.stat("does not exist")
except EnvironmentError as exc:
    err = exc.strerror

pylint --version output

pylint 2.3.0
astroid 2.2.0
Python 3.6.7 (v3.6.7:6ec5cf2, Oct 22 2018, 11:29:07) 
[GCC 4.8.4]
@PCManticore
Copy link
Contributor

Yikes, thanks for reporting the issue! What's happening is that the inference engine is dumb and can't limit the inference of e from the second except handler, resulting in inferring both e as both Error and EnvironmentError. We should definitely address this in astroid.

@PCManticore
Copy link
Contributor

This is fixed in astroid's master which is going to be astroid 2.3.0 when launched.

PCManticore added a commit to pylint-dev/astroid that referenced this issue Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment