Skip to content
Open
16 changes: 16 additions & 0 deletions Doc/library/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ build applications which provide an interactive interpreter prompt.
raises :exc:`OverflowError` or :exc:`ValueError` if the command contains an
invalid literal.

Overriding Console Output
-------------------------

All output is printed to :data:`sys.stderr` by default. A user can override
:meth:`InteractiveConsole.write` in a derived class to change that. Alternatively,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap this so that no line is more than 80 chars.

Before we make this documented behavior, let's make sure that there are unit tests ensuring it is true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are tests for excepthook, but not for displayhook:
https://github.com/python/cpython/blob/main/Lib/test/test_code_module.py

it is possible to selectively redirect parts of the output:

* The return values of successfully interpreted Python statements are printed
with :func:`sys.displayhook`.
* Exception tracebacks and syntax errors can be redirected by setting
:func:`sys.excepthook`.

Additionally, :class:`InteractiveConsole` will print banner information to
:data:`sys.stderr` if *banner* was passed to the constructor.



.. _interpreter-objects:

Expand Down
5 changes: 3 additions & 2 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ are always available. They are listed here in alphabetical order.
The *mode* argument specifies what kind of code must be compiled; it can be
``'exec'`` if *source* consists of a sequence of statements, ``'eval'`` if it
consists of a single expression, or ``'single'`` if it consists of a single
interactive statement (in the latter case, expression statements that
evaluate to something other than ``None`` will be printed).
interactive statement. In the latter case, expression statements that
evaluate to something other than ``None`` will be printed using
:func:`sys.displayhook`.

The optional arguments *flags* and *dont_inherit* control which
:ref:`compiler options <ast-compiler-flags>` should be activated
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update to documentation.