Skip to content

Data entered through input() in REPL is written to ~/.python_history #159225

Open

Description

@ThiefMaster

Bug report

[adrian@eluvian:~]> python
Python 3.15.0 (main, Oct  9 2026, 23:29:57) [GCC 16.2.1 20260926] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> input()
hello world, this may be secret!
'hello world, this may be secret!'
>>>

[adrian@eluvian:~]> tail -n2 ~/.python_history
input()
hello world, this may be secret!

I know there's getpass.getpass() for secrets, but I'm sure it's not uncommon that people just run quick&dirty snippeds in the python repl where they use input() to enter a password without expecting it to be written to their history.

The security aspect aside, it also feels very dirty because unlike the rest of content in the history file, a line entered through input() is very unlikely to make sense when executed as python code (e.g. from the REPL history).

CPython versions tested on:

3.12, 3.15

Operating systems tested on:

Linux

Linked PRs

Activity

  1. hugovk commented on Oct 12, 2026

    @hugovk
    Member

    Duplicate of #71057?

  2. BHUVANSH855 commented on Oct 12, 2026

    @BHUVANSH855
    Contributor

    This appears related to #71057, but could we verify whether readline.set_auto_history(False) also prevents input() responses from being recorded when using the default PyREPL? PyREPL has a separate history implementation, so the behavior may differ.

  3. lazerg commented on Oct 12, 2026

    @lazerg
    Contributor

    I tried it on 3.14.8 with the default REPL and PYTHON_HISTORY pointed at a temp file. readline.set_auto_history(False) doesn't help there, the input() reply still ends up in the history file. PyREPL replaces builtins.input with its own reader (readline.py#L640-L641), and that reader appends every line to the shared history (historical_reader.py#L411-L412), so the C module's flag is never consulted.

    The private _pyrepl.readline.set_auto_history(False) does stop it, but it turns off history for everything typed afterwards, not just input(). Same with the C module under PYTHON_BASIC_REPL=1. So right now there's no way to skip only the input() lines.

  4. edvilme commented on Oct 12, 2026

    @edvilme
    Contributor

    Hi if people are not planning to already, would love to work on this :)

  5. added
    stdlibStandard Library Python modules in the Lib/ directory
    topic-replRelated to the interactive shell
    on Oct 12, 2026
  6. edvilme commented on Oct 12, 2026

    @edvilme
    Contributor

    I wonder if the behavior we want is to disable history while on input() mode, or if we should still allow using up/down arrows while on input() mode but just not adding anything to it

  7. added 4 commits that reference this issue on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions