[Python-ideas] with None (Was: Re: Enhanced context managers with ContextManagerExit and None)

Serhiy Storchaka storchaka at gmail.com
Tue Aug 13 21:19:05 CEST 2013


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.



More information about the Python-ideas mailing list