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

Add isinstance in if condition check as a special case #1990

Closed
a4abhishek opened this issue Apr 3, 2018 · 2 comments · Fixed by #4764
Closed

Add isinstance in if condition check as a special case #1990

a4abhishek opened this issue Apr 3, 2018 · 2 comments · Fixed by #4764
Labels
Control flow Requires control flow understanding
Milestone

Comments

@a4abhishek
Copy link

a4abhishek commented Apr 3, 2018

Steps to reproduce

  1. Write this simple code and save it:
import subprocess

try:
    subprocess.check_call(['ls', '-']) # Deliberately made error in this line
except Exception as err:
    if isinstance(err, subprocess.CalledProcessError):
        print 'Subprocess error occured. Return code:', err.returncode
        # Error in above line.......................here^^^
    else:
        print 'An error occured:', str(err)
  1. Run pylint on this file.
  2. Output of Pylint:
$ pylint pylint_test.py 
No config file found, using default configuration
************* Module pylint_test
C:  1, 0: Missing module docstring (missing-docstring)
W:  5, 7: Catching too general exception Exception (broad-except)
E:  7,56: Instance of 'Exception' has no 'returncode' member (no-member)

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

Current behavior

I is showing Error in line: 7 which should not be an error.

Expected behavior

It should not show Error in line-7 as I am already checking if err is an instance of subprocess.CalledProcessError which has member returncode.

pylint --version output

No config file found, using default configuration
pylint 1.8.3, 
astroid 1.6.2
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609]
@PCManticore
Copy link
Contributor

Thanks for creating this issue @a4abhishek ! This is a well known problem to us, we simply don't support any control flow understanding whatsoever right now, basically we disregard any if guard and infer the potential values of a variable from all the branches, which is the reason why you're also seeing this error. There is no progress yet, but we have dozens of issues that will be solved once we'll add this inference support.

@PCManticore PCManticore added the Control flow Requires control flow understanding label Apr 4, 2018
@a4abhishek
Copy link
Author

Thanks @PCManticore for considering this.

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

Successfully merging a pull request may close this issue.

3 participants