It does not, it works like a C++ destructor, the context management code is static, and anything it needs is provided as a parameter.
While "ad-hoc" context managers are possible (and quite trivial in fact):
1. I don't remember ever wanting one
2. they would not be convenient owing to Python's limited lambdas so
3. you'd probably implement them using a ~decorator on a nested function instead which
4. may look quite odd to most Python developers
It does not, it works like a C++ destructor, the context management code is static, and anything it needs is provided as a parameter.
While "ad-hoc" context managers are possible (and quite trivial in fact):
1. I don't remember ever wanting one
2. they would not be convenient owing to Python's limited lambdas so
3. you'd probably implement them using a ~decorator on a nested function instead which
4. may look quite odd to most Python developers