Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e40cec

Browse files
committed
whatsnew: sys.__interactivehook__. (#5845)
I decided to leave the (slightly expanded) Other Improvements entry as well, since someone looking for command line behavior changes isn't going to look in the 'sys' module section.
1 parent 04ea3f3 commit 4e40cec

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

Doc/library/site.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,13 @@ On systems that support :mod:`readline`, this module will also import and
123123
configure the :mod:`rlcompleter` module, if Python is started in
124124
:ref:`interactive mode <tut-interactive>` and without the :option:`-S` option.
125125
The default behavior is enable tab-completion and to use
126-
:file:`~/.python_history` as the history save file. To disable it, override
127-
the :data:`sys.__interactivehook__` attribute in your :mod:`sitecustomize`
128-
or :mod:`usercustomize` module or your :envvar:`PYTHONSTARTUP` file.
126+
:file:`~/.python_history` as the history save file. To disable it, delete (or
127+
override) the :data:`sys.__interactivehook__` attribute in your
128+
:mod:`sitecustomize` or :mod:`usercustomize` module or your
129+
:envvar:`PYTHONSTARTUP` file.
130+
131+
.. versionchanged:: 3.4
132+
Activation of rlcompleter and history was made automatic.
129133

130134

131135
Module contents

Doc/library/sys.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,11 @@ always available.
692692

693693
.. data:: __interactivehook__
694694

695-
When present, this function is automatically called (with no arguments)
696-
when the interpreter is launched in :ref:`interactive mode <tut-interactive>`.
697-
This is done after the :envvar:`PYTHONSTARTUP` file is read, so that you
698-
can set this hook there.
695+
When this attribute exists, its value is automatically called (with no
696+
arguments) when the interpreter is launched in :ref:`interactive mode
697+
<tut-interactive>`. This is done after the :envvar:`PYTHONSTARTUP` file is
698+
read, so that you can set this hook there. The :mod:`site` module
699+
:ref:`sets this <rlcompleter-config>`.
699700

700701
.. versionadded:: 3.4
701702

Doc/whatsnew/3.4.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,19 @@ blocks allocated by the interpreter (in CPython with the default
13601360
especially if automated via a test suite. (Contributed by Antoine Pitrou
13611361
in :issue:`13390`.)
13621362

1363+
When the Python interpreter starts in :ref:`interactive mode
1364+
<tut-interactive>`, it checks for an :data:`~sys.__interactivehook__` attribute
1365+
on the :mod:`sys` module. If the attribute exists, its value is called with no
1366+
arguments just before interactive mode is started. The check is made after the
1367+
:envvar:`PYTHONSTARTUP` file is read, so it can be set there. The :mod:`site`
1368+
module :ref:`sets it <rlcompleter-config>` to a function that enables tab
1369+
completion and history saving (in :file:`~/.python-history`) if the platform
1370+
supports :mod:`readline`. If you do not want this (new) behavior, you can
1371+
override it in :envvar:`PYTHONSTARTUP`, :mod:`sitecustomize`, or
1372+
:mod:`usercustomize` by deleting this attribute from :mod:`sys` (or setting it
1373+
to some other callable). (Contributed by Éric Araujo and Antoine Pitrou in
1374+
:issue:`5845`.)
1375+
13631376

13641377
textwrap
13651378
--------
@@ -1694,7 +1707,9 @@ Other Improvements
16941707
most POSIX systems it can and should be used in the ``#!`` line of system
16951708
scripts. (Contributed by Christian Heimes in :issue:`16499`.)
16961709

1697-
* Tab-completion is now enabled by default in the interactive interpreter.
1710+
* Tab-completion is now enabled by default in the interactive interpreter
1711+
on systems that support :mod:`readline`. History is also enabled by default,
1712+
and is written to (and read from) the file :file:`~/.python-history`.
16981713
(Contributed by Antoine Pitrou and Éric Araujo in :issue:`5845`.)
16991714

17001715
* Invoking the Python interpreter with ``--version`` now outputs the version to

0 commit comments

Comments
 (0)