Aug. 14, 2013
3:19 a.m.
13.08.13 18:29, Masklinn написав(ла):
If you want an optional context manager, why not create an OptionalContextManager(object | None) which delegates to the underlying non-None CM? That's simple, that's clear, that's explicit, and that's not a hack.
Because OptionalContextManager doesn't support an interface of the underlying object (e.g. doesn't have the read() method). And OptionalContextManager(None) is not None.