There's been this warning for at least 6 months :
/usr/lib64/python2.7/site-packages/IPython/terminal/interactiveshell.py:432: DeprecationWarning: With-statements now directly support multiple context managers
By default DeprecationWarning are not displayed, but within some environments (typically : django 'shell' command), they are.
Numerous tickets are open in Django about this, but this need to be fixed in ipython, not Django.
You don't state which version of IPython this is but if you inspect the IPython source it looks like this is present in 1.x but already fixed in master (what will become 2.x).
The warning cannot be fixed in 1.x since multiple contexts were first added in python 2.7 and 1.x still support python 2.6 (http://docs.python.org/dev/whatsnew/2.7.html). Furthermore the deprecation warning looks totally harmless.
@jenshnielsen was faster than me to answer.
Will reopen if it is still an issue on master.
I'm using ipython 1.1.0
I'm not familiar with this, but wont writing something like
work both with python 2.6 and upper ?
Yes exactly as the present behaviour does. That is exactly the deprecationwarning is suggesting not to do.
What the message says is: Note that now you can write
with self.builtin_trap, self.display_trap:
It does not indicate that the old nesting will stop working at any point.
I tried this code on python 2.6 and 2.7, and it worked / had no warning whatsoever :
from threading import Lock
a,b = Lock(), Lock()
Ok the story appears to be.
The simplest implementation is the explicitly nested statements. To simplify this the nested key word in the
contextlib makes it possible to write code of the type used in IPython 1.x at the moment.
from contextlib import nested
with nested(A(), B(), C()) as (X, Y, Z):
this has in 2.7 been replaced by
with A(), B(), C():
And the second behaviour is deprecated.
To make sure this works in all python versions IPython 1.x contains code like this:
from contextlib import nested
from IPython.utils.nested_context import nested
Which explicitly falls back on it's own version in the one in contextlib is removed.
A depreciation warning only means that this code may break in a later python version which will
not happen since there already is a fallback in place for newer versions.
This is only used in three files :
and for each file it is used only once in the file. Every use of nested() is with exactly two args, no more. It's not as if nested() was a crucial help there.
If you replace this by just nesting 'by hand' without using any "nested", not only will it work silently with Django, which would be very nice for us, but also you could remove the file ./utils/nested_context.py altogether and simplify the import statements in those 3 files.
If you really want to use your nested stuff, at least, use it on python 2.7 too
Currently on 2.7, the statement "from contextlib import nested" works but raises the warning. Python 2.7 is by far the most common version in use today...
But the nested with statement are removed on master, so is IPython/utils/nested_context.py.
And on master we dropped support for 2.6 and 3.2.
We can potentially do that for a 1.2.0 release.
You can try to open a Pull request.