Never had such a small code excerpt hint at so much complexity before. Both value and tb are stateful, tb needs to be compared with is against a traceback, value is thrown, apparently to the calling scope and then reset in the finally block and so the order of execution of exception handling is relevant. What a mess!
It's actually meant to re-raise an exception with the given traceback. The point is... the finally block is at the end of the function... so why assign None to the variables.
try:
if value is None:
value = tp()
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value
finally:
value = None
tb = None
else:
ord2 = ord
11
u/[deleted] Dec 31 '21
Truly bad code
5
u/youngbull Dec 31 '21
Never had such a small code excerpt hint at so much complexity before. Both value and tb are stateful, tb needs to be compared with
isagainst a traceback, value is thrown, apparently to the calling scope and then reset in the finally block and so the order of execution of exception handling is relevant. What a mess!6
u/GenericRedditUser_ Dec 31 '21 edited Dec 31 '21
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!