Opened 13 years ago
Closed 12 years ago
#18204 closed Bug (duplicate)
manage.py shell w/ IPython embed does not work well
Reported by: | liokm | Owned by: | nobody |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
#17078 introduced the usage of IPython.embed()
. This also introduced the bug described in the bottom part of https://github.com/ipython/ipython/issues/62 to the IPython shell opened by Django. For example:
>>> def foo(): ... print foo >>> foo() ... NameError: global name 'foo' is not defined
The issue https://github.com/ipython/ipython/issues/62 just solved for normal IPython shell, not for embed
calling from function, which is used in current Django, as in django/core/management/commands/shell.py
def ipython(self): ... from IPython import embed embed() ...
Some quotes of takluyver from IPython team in the github link above
It's possible for Django to start IPython in a way that won't cause this problem, but that's not the way we currently make easy. The problem occurs when IPython starts with separate local and global namespaces. There's no reason that Django requires separate local and global namespaces, but that's what calling embed() inside a function implies.
My env: Django 1.4 and 1.5 alpha w/ IPython 0.12 and 0.12.1
Attachments (2)
Change History (9)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Description: | modified (diff) |
---|
comment:3 by , 13 years ago
Has patch: | set |
---|
Here is a stab at fixing this. The workaround is to put the embed code in its own module, so that it has its own namespace. It's ugly to have to put it in source form in the utils tree.
Errr, while typing this, I had a brainwave. Give me a sec.
comment:4 by , 13 years ago
Much better way of fixing this. Basically, execute embed() in a new global context via the "exec ... in ..." construct.
I will try bpython as well, to see if they have the same issue.
comment:5 by , 13 years ago
Nope, bpython seems immune. They probably do something like this internally.
by , 13 years ago
Attachment: | embed-ipython-module.2.diff added |
---|
by , 13 years ago
Attachment: | embed-ipython-module.diff added |
---|
comment:6 by , 12 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
I'd rather use an own module to handle this, instead of using exec or eval.
comment:7 by , 12 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Closing this as a duplicate of the now revived #17078
Ah, sorry for bad formatting w/o preview, could someone help to fix it?