MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / _reset_py_display

Method _reset_py_display

cmd2/cmd2.py:4801–4820  ·  view source on GitHub ↗

Reset the dynamic objects in the sys module that the py and ipy consoles fight over. When a Python console starts it adopts certain display settings if they've already been set. If an ipy console has previously been run, then py uses its settings and ends up looking like an

()

Source from the content-addressed store, hash-verified

4799
4800 @staticmethod
4801 def _reset_py_display() -> None:
4802 """Reset the dynamic objects in the sys module that the py and ipy consoles fight over.
4803
4804 When a Python console starts it adopts certain display settings if they've already been set.
4805 If an ipy console has previously been run, then py uses its settings and ends up looking
4806 like an ipy console in terms of prompt and exception text. This method forces the Python
4807 console to create its own display settings since they won't exist.
4808
4809 IPython does not have this problem since it always overwrites the display settings when it
4810 is run. Therefore, this method only needs to be called before creating a Python console.
4811 """
4812 # Delete any prompts that have been set
4813 attributes = ["ps1", "ps2", "ps3"]
4814 for cur_attr in attributes:
4815 with contextlib.suppress(KeyError):
4816 del sys.__dict__[cur_attr]
4817
4818 # Reset functions
4819 sys.displayhook = sys.__displayhook__
4820 sys.excepthook = sys.__excepthook__
4821
4822 def _set_up_py_shell_env(self, interp: InteractiveConsole) -> _SavedCmd2Env:
4823 """Set up interactive Python shell environment.

Callers 1

_set_up_py_shell_envMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected