Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-12403: Mention sys.displayhook in code module docs and the compile builtin docs #26217

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
19 changes: 19 additions & 0 deletions Doc/library/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ build applications which provide an interactive interpreter prompt.
raises :exc:`OverflowError` or :exc:`ValueError` if the command contains an
invalid literal.

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

To customize console output a user can replace :func:`sys.displayhook`
and/or :func:`sys.excepthook`. Alternatively, users can override
:meth:`InteractiveConsole.write` in a derived class.

The destination of console output is controlled as follows:

* The return value from successfully interpreted Python statements are printed
by calling :func:`sys.displayhook`. This is a side effect of
:func:`compile_command` passing ``'single'`` for *symbol*.
* Exception tracebacks and syntax errors are written to :data:`sys.stderr` by
default but 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.

iritkatriel marked this conversation as resolved.
Show resolved Hide resolved

iritkatriel marked this conversation as resolved.
Show resolved Hide resolved

.. _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
normanlorrain marked this conversation as resolved.
Show resolved Hide resolved
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.
normanlorrain marked this conversation as resolved.
Show resolved Hide resolved