Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#32363 closed New feature (fixed)

Django shell does not read ~/.python_history

Reported by: Peter Inglesby Owned by: Peter Inglesby
Component: Core (Management commands) Version: 4.0
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (10)

comment:1 by Peter Inglesby, 4 years ago

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()__ in site.py, and I'm not sure what would happen if that was duplicated.

comment:2 by Peter Inglesby, 4 years ago

Has patch: set

comment:3 by Peter Inglesby, 4 years ago

Component: UncategorizedCore (Management commands)
Type: UncategorizedBug

comment:4 by Carlton Gibson, 4 years ago

Triage Stage: UnreviewedAccepted
Type: BugNew feature

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.

comment:5 by Mariusz Felisiak, 4 years ago

Owner: changed from nobody to Peter Inglesby
Status: newassigned

comment:6 by Carlton Gibson, 4 years ago

Patch needs improvement: set

There's unresolved debate on the PR about whether the current proposal is acceptable. Marking PNI whilst that's concluded (either way).

comment:7 by Carlton Gibson, 3 years ago

Patch needs improvement: unset

comment:8 by Carlton Gibson, 3 years ago

Triage Stage: AcceptedReady for checkin
Version: 3.14.0

comment:9 by Carlton Gibson <carlton.gibson@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In 1bbb98d:

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.

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In 3921b1c6:

Refs #32363 -- Made shell ignore a missing sys._interactivehook.

Thanks Tim Graham for the report.

Follow up to 1bbb98d9a4b7d83e422b14ae2429cb368eff5a13.

Note: See TracTickets for help on using tickets.
Back to Top