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 for catching-non-exception #125

Closed
pylint-bot opened this issue Jan 1, 2014 · 6 comments
Closed

false positive for catching-non-exception #125

pylint-bot opened this issue Jan 1, 2014 · 6 comments
Labels
Bug 🪲 Checkers Related to a checker

Comments

@pylint-bot
Copy link

Originally reported by: Anonymous


when i create a class that inherits from socket.error (which inherits from Exception), and use the new class in a try/except block, i receive a pylint error message stating that i am "catching a exception which doesn't inherit from BaseException: (catching-non-exception)"

eg:

from socket import error

class MyError(error): pass

try:
print 'a'
except MyError:
print 'b'


@pylint-bot
Copy link
Author

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


Solved with https://bitbucket.org/logilab/pylint/pull-request/78/fix-false-positive-for-catching-non/diff. Thanks for the report!

@pylint-bot
Copy link
Author

Original comment by BitBucket: benzionhain:


Thanks for the quick response and fix.

another reason to love pylint :)

ben

@pylint-bot
Copy link
Author

Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?):


Removing version: 1.1 (automated comment)

@pylint-bot pylint-bot added Bug 🪲 Checkers Related to a checker labels Dec 9, 2015
@dhermes
Copy link
Contributor

dhermes commented Jul 18, 2016

@PCManticore There may be a regression here, triggered in https://github.com/GoogleCloudPlatform/gcloud-python

To reproduce, install grpcio==0.15.0, then

"""Bogus docstring."""


from grpc.framework.interfaces.face import face

try:
    MY_GLOBAL = 11
except face.NetworkError:
    raise ValueError('Other error')

then the error is

$ pylint foo.py
No config file found, using default configuration
************* Module foo
E:  8, 7: Catching an exception which doesn't inherit from BaseException: NetworkError (catching-non-exception)

But note that the MRO contains BaseException (and also Exception FWIW)

>>> from grpc.framework.interfaces.face import face
D0718 16:12:55.983836848   26996 ev_posix.c:101]             Using polling engine: poll
>>> face.NetworkError.__mro__
(<class 'grpc.framework.interfaces.face.face.NetworkError'>, <class 'grpc.framework.interfaces.face.face.AbortionError'>, <type 'exceptions.Exception'>, <type 'exceptions.BaseException'>, <type 'object'>)

It's possible that there is some sort of failure in the static analysis caused by usage of six.with_metaclass(abc.ABCMeta, Exception) in the parent?

@PCManticore
Copy link
Contributor

@dhermes Should be fixed by 8d35557. Will release 1.6.4 later today or early tomorrow.

@dhermes
Copy link
Contributor

dhermes commented Jul 19, 2016

@PCManticore You are awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Checkers Related to a checker
Projects
None yet
Development

No branches or pull requests

3 participants