Skip to content

Context Managers

Support for the with statement.

operator operands
expression method(s) type(s)
__enter__ CanEnter[+C], or
CanEnterSelf
__exit__ CanExit[+R = None]
with _ as c: ... __enter__ & __exit__ CanWith[+C, +R = None], or
CanWithSelf[+R = None]

CanEnterSelf and CanWithSelf are (runtime-checkable) aliases for CanEnter[Self] and CanWith[Self, R], respectively.

For the async with statement the interfaces look very similar: