You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Foo(Exception):
""" Exception wrapper
"""
def __init__(self, code):
super(Foo, self).__init__()
self.response = {'Error': {'Code': code}}
def dynamic_exc(code):
""" Dynamically determine what exception
"""
import sys
dummy, exc, dummy = sys.exc_info()
if isinstance(exc, Foo) and exc.response['Error']['Code'] == code:
return Foo
return type('OtherException', (Exception,), {})
try:
raise Foo('403')
except dynamic_exc('403') as ex:
print('The dynamic exception {0}'.format(ex))
except Foo as ex:
print('Caught general Foo exception {0}'.format(ex))
try:
raise Foo('404')
except dynamic_exc('403') as ex:
print('The dynamic exception {0}'.format(ex))
except Foo as ex:
print('Caught general Foo exception {0}'.format(ex))
Current behavior
W: 25, 7: Catching previously caught exception type Foo (duplicate-except)
W: 33, 7: Catching previously caught exception type Foo (duplicate-except)
pylint gives a duplicate-except warning for dynamic exceptions that may not be duplicates
Expected behavior
I would expect differentiation between dynamically handled exceptions and static duplicates like below so warnings for dynamic exceptions can be turned off without masking static duplicates.
try:
raise Foo('404')
except Foo as ex:
print('Caught general Foo exception {0}'.format(ex))
except Foo as ex:
print('Caught general Foo exception {0}'.format(ex))
pylint --version output
No config file found, using default configuration
pylint 1.9.2,
astroid 1.6.5
Python 3.6.0 (default, Aug 8 2017, 09:49:26)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
The text was updated successfully, but these errors were encountered:
The problem comes from the if check you're doing in that dynamic function, which pylint has no way of understanding, especially since the information comes from sys.exc_info. I suggest just refactoring the way you're using these dynamic exceptions as it is a bit confusing on what is going to catch anyway, or just disable the error in place.
Steps to reproduce
Current behavior
pylint gives a duplicate-except warning for dynamic exceptions that may not be duplicates
Expected behavior
I would expect differentiation between dynamically handled exceptions and static duplicates like below so warnings for dynamic exceptions can be turned off without masking static duplicates.
pylint --version output
The text was updated successfully, but these errors were encountered: