In particular ExitStacks are useful when you have 0 or 1 resources. It allows a sort of null-context manager for when the number of resources you have to allocate might be 0.
ctx_mgr = foo() if bar else nullcontext()
with ctx_mgr:
...
if you like. with (ctx_mgr := foo() if bar else nullcontext()):
...