diff options
| author | Peter Inglesby <peter.inglesby@gmail.com> | 2021-09-05 20:38:36 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-09-06 10:18:13 +0200 |
| commit | 3921b1c6d24c9d5a60e5f5f83c9a394104089c21 (patch) | |
| tree | 9d380b2a04ba0c2bfb8241cbca3f6304e317508e | |
| parent | a7f27fca5239ff3840735dc6dc731b71a99a1d57 (diff) | |
Refs #32363 -- Made shell ignore a missing sys.___interactivehook__.
Thanks Tim Graham for the report.
Follow up to 1bbb98d9a4b7d83e422b14ae2429cb368eff5a13.
| -rw-r--r-- | django/core/management/commands/shell.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/django/core/management/commands/shell.py b/django/core/management/commands/shell.py index fe24f4b3fb..cbd4c86620 100644 --- a/django/core/management/commands/shell.py +++ b/django/core/management/commands/shell.py @@ -66,12 +66,20 @@ class Command(BaseCommand): # write history to the .python_history file, but this can be overridden by # $PYTHONSTARTUP or ~/.pythonrc.py. try: - sys.__interactivehook__() - except Exception: - # Match the behavior of the cpython shell where an error in - # sys.__interactivehook__ prints a warning and the exception and continues. - print("Failed calling sys.__interactivehook__") - traceback.print_exc() + hook = sys.__interactivehook__ + except AttributeError: + # Match the behavior of the cpython shell where a missing + # sys.__interactivehook__ is ignored. + pass + else: + try: + hook() + except Exception: + # Match the behavior of the cpython shell where an error in + # sys.__interactivehook__ prints a warning and the exception + # and continues. + print('Failed calling sys.__interactivehook__') + traceback.print_exc() # Set up tab completion for objects imported by $PYTHONSTARTUP or # ~/.pythonrc.py. |
