This is because `sys.__interactivehook__()` is not called in shell.py.
Adding
{{{
try:
sys.__interactivehook__()
except Exception:
print("Failed calling sys.__interactivehook__")
traceback.print_exc()
}}}
just before the call to `code.interpret()` in shell.py fixes this, and
makes the Django shell nearly match the behaviour of the Python shell.
I'll create a PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/32363>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Peter Inglesby):
The fix is possibly a little more complex than that, since Django already
runs some of the code in the default code in `sys.__interactivehook()__`
[https://github.com/python/cpython/blob/master/Lib/site.py#L441-L487 in
site.py], and I'm not sure what would happen if that was duplicated.
--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:1>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:2>
* type: Uncategorized => Bug
* component: Uncategorized => Core (Management commands)
--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:3>
* type: Bug => New feature
* stage: Unreviewed => Accepted
Comment:
> The fix is possibly a little more complex than that...
OK, thanks for the report. If we can get it in without issue then it would
be a nice addition.
--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:4>
* owner: nobody => Peter Inglesby
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:5>
* needs_better_patch: 0 => 1
Comment:
There's unresolved debate on the PR about whether the current proposal is
acceptable. Marking ''PNI'' whilst that's concluded (either way).
--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:6>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:7>
* version: 3.1 => 4.0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"1bbb98d9a4b7d83e422b14ae2429cb368eff5a13" 1bbb98d]:
{{{
#!CommitTicketReference repository=""
revision="1bbb98d9a4b7d83e422b14ae2429cb368eff5a13"
Fixed #32363 -- Ensured sys.__interactivehook__ is called in shell
By default, this means that readline is properly registered, so that
.python_history is used.
sys.__interactivehook__ may be set by a $PYTHONSTARTUP file.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:9>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"3921b1c6d24c9d5a60e5f5f83c9a394104089c21" 3921b1c6]:
{{{
#!CommitTicketReference repository=""
revision="3921b1c6d24c9d5a60e5f5f83c9a394104089c21"
Refs #32363 -- Made shell ignore a missing sys.___interactivehook__.
Thanks Tim Graham for the report.
Follow up to 1bbb98d9a4b7d83e422b14ae2429cb368eff5a13.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:10>