Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django: manage.py shell - DeprecationWarning regarding the with statement #29

Closed
matematikaadit opened this issue Dec 11, 2013 · 1 comment
Labels

Comments

@matematikaadit
Copy link
Owner

TLDR

create a new file in:
$HOME/.config/ipython/profile_default/startup/00-disable-deprecation-warning.py

then put following content:

# hide deprecation warning
# IPython/terminal/interactiveshell.py:432:
# DeprecationWarning: With-statements now directly ...

import warnings
import exceptions
warnings.filterwarnings("ignore",
    category=exceptions.DeprecationWarning,
    module='IPython.terminal.interactiveshell',
    lineno=432) # change lineno to your line number warning

change lineno to your line number warning and module to module that give that warning. Since it's a DeprecationWarning, use that appropriate category.

The Issue

Version of affected program:

  • Django 1.6
  • IPython 1.1.0

This issue happen in a fresh Django project.

When you start python manage.py shell in a IPython shell, you'll encounter this
Deprecation warning

/home/adit/.virtualenv/local/lib/python2.7/site-packages/
IPython/terminal/interactiveshell.py:432: DeprecationWarning: With-statements now 
directly support multiple context managers
  with nested(self.builtin_trap, self.display_trap):

This issue was reported in https://code.djangoproject.com/ticket/19789
But, that was invalid since the actual issue is on the IPython side. The link to the IPython github issue was this: ipython/ipython#4455

Reading the discussion, you'll notice that it was fixed in the 2.x version of IPython
(the master branch). So, you won't get it fixed in the current version unless someone (?) give a pull request to fix it.

Workaround

A work around to fix this warning is by using IPython configuration.
http://ipython.org/ipython-doc/stable/config/overview.html

Based on the documentation link above, IPython configuration file location was searched in the following directory:

  • direcotry that given to --ipython-dir=<directory> command line flag
  • $HOME/.config/ipython (in Unix, Linux, etc.)
  • $HOME/.ipython

In that order above. The first found will be used. Refer to the documentation for more explanation.

Anyway, you could execute following command to find your configuration directory.

$ ipython locate
/home/adit/.config/ipython

In the directory that given by the output of the command above, you'll find profile_default directory. (to generate the file if it doesn't exist execute ipython profile create).

On the subfolder startup of the above directory, you could put any python script (.py) or IPython script (.ipy) that will be executed in lexicographic order when you start IPython.

Create following file in that folder

# hide deprecation warning
# IPython/terminal/interactiveshell.py:432:
# DeprecationWarning: With-statements now directly ...

import warnings
import exceptions
warnings.filterwarnings("ignore",
    category=exceptions.DeprecationWarning,
    module='IPython.terminal.interactiveshell',
    lineno=432) # change lineno to your line number warning

Take a note of your warning, change the module and lineno parameter according
your case.

For my case, I get this line in the warning:

IPython/terminal/interactiveshell.py:432: DeprecationWarning: ...(snip)...

That means I must cange category to execption.DeprecationWarning, module toIPython.terminal.interactiveshell, and lineno to 432.

Give that file any name you want, for example: 00-disable-deprecation-warning.py and save it.

Now, when you start IPython the deprecation warning will disappear.

@loisaidasam
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants