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

Terry Reedy tjreedy at udel.edu
Tue Aug 13 19:45:48 CEST 2013


On 8/13/2013 10:48 AM, Serhiy Storchaka wrote:

>> None becomes the trivial context manager and its __enter__ and
>> __exit__ calls are skipped, along with their overhead.

> And when the with statement will support None as a "null-manager":

As I understand the proposal, it is not to actually make None a context 
manager with __enter__ and __exit__ methods (bad), but to make it a 
signal to not do the normal calls. Such a use of None as a 'skip' signal 
is similar to its use as function argument.

While such use is fine when None is a default argument (the normal 
case), its use in filter for a required argument is problematical (see 
recent thread here). I think using None as a signal object here would 
engender the same confusion here. "How can None be a context manager if 
it does not have the ... methods?"

Given the alternative of an empty stack and a possible addition to 
contextlib, I do not think we should go for this generalization of None 
usage.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list