[Django] #32363: Django shell does not read ~/.python_history

38 views
Skip to first unread message

Django

unread,
Jan 18, 2021, 11:28:08 AM1/18/21
to django-...@googlegroups.com
#32363: Django shell does not read ~/.python_history
------------------------------------------+------------------------
Reporter: Peter Inglesby | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+------------------------
The Django shell does not read ~/.python_history.

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.

Django

unread,
Jan 18, 2021, 11:34:43 AM1/18/21
to django-...@googlegroups.com
#32363: Django shell does not read ~/.python_history
--------------------------------+--------------------------------------

Reporter: Peter Inglesby | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------

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>

Django

unread,
Jan 18, 2021, 2:25:16 PM1/18/21
to django-...@googlegroups.com
#32363: Django shell does not read ~/.python_history
--------------------------------+--------------------------------------

Reporter: Peter Inglesby | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Peter Inglesby):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:2>

Django

unread,
Jan 18, 2021, 2:26:35 PM1/18/21
to django-...@googlegroups.com
#32363: Django shell does not read ~/.python_history
-------------------------------------+-------------------------------------

Reporter: Peter Inglesby | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Peter Inglesby):

* type: Uncategorized => Bug
* component: Uncategorized => Core (Management commands)


--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:3>

Django

unread,
Jan 19, 2021, 2:10:59 AM1/19/21
to django-...@googlegroups.com
#32363: Django shell does not read ~/.python_history
-------------------------------------+-------------------------------------

Reporter: Peter Inglesby | Owner: nobody
Type: New feature | Status: new

Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* 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>

Django

unread,
Jan 19, 2021, 2:16:08 AM1/19/21
to django-...@googlegroups.com
#32363: Django shell does not read ~/.python_history
-------------------------------------+-------------------------------------
Reporter: Peter Inglesby | Owner: Peter
| Inglesby
Type: New feature | Status: assigned

Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Peter Inglesby
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:5>

Django

unread,
Jun 16, 2021, 6:14:11 AM6/16/21
to django-...@googlegroups.com
#32363: Django shell does not read ~/.python_history
-------------------------------------+-------------------------------------
Reporter: Peter Inglesby | Owner: Peter
| Inglesby
Type: New feature | Status: assigned
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* 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>

Django

unread,
Jun 22, 2021, 6:18:10 AM6/22/21
to django-...@googlegroups.com
#32363: Django shell does not read ~/.python_history
-------------------------------------+-------------------------------------
Reporter: Peter Inglesby | Owner: Peter
| Inglesby
Type: New feature | Status: assigned
Component: Core (Management | Version: 3.1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:7>

Django

unread,
Jun 22, 2021, 9:18:29 AM6/22/21
to django-...@googlegroups.com
#32363: Django shell does not read ~/.python_history
-------------------------------------+-------------------------------------
Reporter: Peter Inglesby | Owner: Peter
| Inglesby
Type: New feature | Status: assigned
Component: Core (Management | Version: 4.0
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* version: 3.1 => 4.0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32363#comment:8>

Django

unread,
Jun 23, 2021, 9:24:31 AM6/23/21
to django-...@googlegroups.com
#32363: Django shell does not read ~/.python_history
-------------------------------------+-------------------------------------
Reporter: Peter Inglesby | Owner: Peter
| Inglesby
Type: New feature | Status: closed

Component: Core (Management | Version: 4.0
commands) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson <carlton.gibson@…>):

* 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>

Django

unread,
Sep 6, 2021, 5:34:53 AM9/6/21
to django-...@googlegroups.com
#32363: Django shell does not read ~/.python_history
-------------------------------------+-------------------------------------
Reporter: Peter Inglesby | Owner: Peter
| Inglesby
Type: New feature | Status: closed
Component: Core (Management | Version: 4.0
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages