Skip to content

Duplicate "except" branch #485

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

Closed
pylint-bot opened this issue Mar 10, 2015 · 10 comments
Closed

Duplicate "except" branch #485

pylint-bot opened this issue Mar 10, 2015 · 10 comments
Labels
Enhancement ✨ Improvement to a component

Comments

@pylint-bot
Copy link

Originally reported by: Steven Myint (BitBucket: myint, GitHub: @myint?)


I wonder if it would be useful for Pylint to detect duplicate except branches. For example, I ran into something like this today:

def main():
    try:
        # ...
        pass
    except ValueError:
        # ...
        pass
    except ValueError:
        # We will never get here since it will be caught above.
        # ...
        pass

Thanks


@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Yes, it's possible. Would you like to work on a patch?

@pylint-bot
Copy link
Author

Original comment by Steven Myint (BitBucket: myint, GitHub: @myint?):


I haven't written a checker before, but I'll see what I can do. I'm guessing I should start by looking at exceptions.py.

@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Yes. If you need any help, feel free to ask, either here or you can find me on IRC on freenode, #pylint.

@pylint-bot
Copy link
Author

Original comment by Steven Myint (BitBucket: myint, GitHub: @myint?):


Given that setup.py uses 2to3, I guess development must be done under Python 2.7.

One thing I noticed after setting up a Python 2 virtualenv and running python setup.py develop is that I can't run pylint while being in the pylint repository directory. If I do that, I get no output other than a report showing a score of 10. If I change to an unrelated directory, pylint gives the normal output.

@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Nope, 2to3 is used only for converting the tests, the rest works under both versions. Hm, didn't know about the problem you're experiencing, I'll have a look.

@pylint-bot
Copy link
Author

Original comment by Steven Myint (BitBucket: myint, GitHub: @myint?):


Actually, the in-pylint-directory problem happens even without virtualenv. It happens with my normally-installed pylint. And it gives some irrelevant warning messages instead:

myint@macpro:~/projects/pylint
$ pylint --report=no setup.py
Warning: option include-ids is deprecated and ignored.
Warning: option symbols is deprecated and ignored.

(By the way, the associated pull request for this issue is pull request #237.)

@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Could you report another issue for that, please? I'll have a look at the pull request later today.

@pylint-bot
Copy link
Author

Original comment by Steven Myint (BitBucket: myint, GitHub: @myint?):


Sure. See issue #494.

@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Add "duplicate-except" checker

It checks if an exception type was already caught previously in the same
try/except. This fixes #485.

@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Thank you!

@pylint-bot pylint-bot added the Enhancement ✨ Improvement to a component label Dec 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

No branches or pull requests

1 participant