[Python-Dev] Iterator version of contextlib.nested

Hagen Fürstenau hfuerstenau at gmx.net
Sat Jun 13 14:45:56 CEST 2009


> The semantic change actually needed to make nested() more equivalent to
> the multi-with statement is for it to accept zero-argument callables
> that create context managers as arguments rather than pre-created
> context managers.

It seems to me that both passing callables which return managers and
passing a generator which yields managers achieve about the same thing.
Are you proposing the former just to avoid introducing a new interface?

> Rather than changing the name of the function, this could be done by
> inspecting the first argument for an "__enter__" method. If it has one,
> use the old semantics (and issue a DeprecationWarning as in 3.1).
> Otherwise, use the proposed new semantics.

I guess this is much too late for 3.1, but could we then at least
un-deprecate "contextlib.nested" for now? As it is, you get a
DeprecationWarning for something like

with contextlib.nested(*my_managers):

without any good way to get rid of it.

- Hagen


More information about the Python-Dev mailing list