Overlapping exceptions (requests.exceptions.RequestException is an ancestor class of requests.exceptions.JSONDecodeError)
71 timeout=30,
72 headers={'Authorization': f'Bearer {response["access_token"]}'},
73 ).json()
74 except (75 requests.exceptions.RequestException,
76 requests.exceptions.JSONDecodeError,
77 ) as exc:
Overlapping exceptions (requests.exceptions.RequestException is an ancestor class of requests.exceptions.JSONDecodeError)
115 params={'oauth2_access_token': response['access_token']},
116 headers={'x-li-format': 'json'},
117 ).json()
118 except (119 requests.exceptions.RequestException,
120 requests.exceptions.JSONDecodeError,
121 ) as exc:
Overlapping exceptions (requests.exceptions.RequestException is an ancestor class of requests.exceptions.JSONDecodeError)
93 params={'oauth2_access_token': response['access_token']},
94 headers={'x-li-format': 'json'},
95 ).json()
96 except ( 97 requests.exceptions.RequestException,
98 requests.exceptions.JSONDecodeError,
99 ) as exc:
Overlapping exceptions (requests.exceptions.RequestException is an ancestor class of requests.exceptions.JSONDecodeError)
75 'redirect_uri': callback_url,
76 },
77 ).json()
78 except ( 79 requests.exceptions.RequestException,
80 requests.exceptions.JSONDecodeError,
81 ) as exc:
Overlapping exceptions (requests.exceptions.RequestException is an ancestor class of requests.exceptions.JSONDecodeError)
54 )
55 },
56 ).json()
57 except (58 client.FlowExchangeError,
59 requests.exceptions.RequestException,
60 requests.exceptions.JSONDecodeError,
Overlapping exceptions (requests.exceptions.RequestException is an ancestor class of requests.exceptions.JSONDecodeError)
72 'Authorization': f'token {response["access_token"]}',
73 },
74 ).json()
75 except ( 76 requests.exceptions.RequestException,
77 requests.exceptions.JSONDecodeError,
78 ) as exc:
Description
Two or more exceptions in the same exception handler clause that are identical or parts of the same inheritance hierarchy (i.e. overlapping). It is recommmend to refactor this.
Not preferred:
class SomeException(Exception):
pass
class SubclassException(SomeException):
pass
try:
raise SubclassException()
except (SomeException, SubclassException):
pass
Here, SubclassException
has been derived from SomeException
, which makes it overlapping.
Preferred:
class SomeException(Exception):
pass
class SubclassException(SomeException):
pass
try:
raise SubclassException()
except SomeException:
pass