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
When an exception handler re-raises or returns, it seems to me that it's better to put the "else" code as a follow-up to the try/except than in a "else".
Eg for the code
importloggingdefreciprocal(n):
try:
rec=1/nprint(f"reciprocal of {n} is {rec}")
returnrecexceptZeroDivisionError:
logging.exception("Exception occurred")
raise
you get TRY300 Consider moving this statement to an else block
but the best for me would be to write:
importloggingdefreciprocal(n):
try:
rec=1/nexceptZeroDivisionError:
logging.exception("Exception occurred")
raiseprint(f"reciprocal of {n} is {rec}")
returnrec
BTW, the current example also seems incorrect as reciprocal returns an implicit None (See RET503 even though it doesn't detect it)
The text was updated successfully, but these errors were encountered:
When an exception handler re-raises or returns, it seems to me that it's better to put the "else" code as a follow-up to the try/except than in a "else".
Eg for the code
you get
TRY300 Consider moving this statement to an
elseblock
but the best for me would be to write:
BTW, the current example also seems incorrect as
reciprocal
returns an implicitNone
(See RET503 even though it doesn't detect it)The text was updated successfully, but these errors were encountered: