Classes have a defineable function __exit__
that allows implementation of a context manager.
It takes the required arguments:
def __exit__(self, exc_type, exc_val, exc_tb):
but I cannot find a definitive definition of what those arguments are and their types.
Here's my best guess of what they are and why, but I'm not entirely sure:
def __exit__(self, exc_type: Exception, exc_val: TracebackException, exc_tb: TracebackType):
exc_type
Python defines a TracebackException
class that accepts an exc_type
argument which is used contextually in the constructor within issubclass
with SyntaxError
, which infers that exc_type
is indeed some sort of Exception
, which SyntaxError
inherits from.
exc_val
Also, in that TracebackException
class is an exc_value
argument that matches up to our exc_val
which seems to have various attributes like __cause__
, __context__
, and other attributes that are all defined in TracebackType
itself. This makes me think that the parameter is itself an instance of TracebackException
.
exc_tb
Python defines a walk_tb function that uses exc_tb
as an argument (manually traced from docs.python.org), and this object appears to have tb_frame
, tb_lineno
, and tb_next
attributes which can be traced back to a TracebackType
class in the typeshed
library.
Thoughts?