Skip to content

PyOS_StdioReadline is printing the prompt on stderr #57078

Closed

Description

@albertz
mannequin
BPO 12869
Nosy @albertz, @vadmium
Superseder
  • bpo-1927: Change input() to always prompt to stderr
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-01-19.02:50:54.156>
    created_at = <Date 2011-08-31.14:38:37.918>
    labels = ['interpreter-core', 'type-bug']
    title = 'PyOS_StdioReadline is printing the prompt on stderr'
    updated_at = <Date 2016-01-19.02:50:54.144>
    user = 'https://github.com/albertz'

    bugs.python.org fields:

    activity = <Date 2016-01-19.02:50:54.144>
    actor = 'martin.panter'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-01-19.02:50:54.156>
    closer = 'martin.panter'
    components = ['Interpreter Core']
    creation = <Date 2011-08-31.14:38:37.918>
    creator = 'Albert.Zeyer'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 12869
    keywords = []
    message_count = 6.0
    messages = ['143256', '196114', '247982', '255077', '255096', '258570']
    nosy_count = 3.0
    nosy_names = ['Albert.Zeyer', 'martin.panter', 'Drekin']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '1927'
    type = 'behavior'
    url = 'https://bugs.python.org/issue12869'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4', 'Python 3.5', 'Python 3.6']

    Activity

    1. albertz commented on Aug 31, 2011

      albertzmannequin
      MannequinAuthor

      PyOS_StdioReadline from Parser/myreadline.c is printing the prompt on stderr.

      I think it should print it on the given parameter sys_stdout. Other readline implementations (like from the readline module) also behave this way.

      Even if it really is supposed to write on stderr, it should use the sys.stderr and not the system stderr.

    2. Drekin commented on Aug 25, 2013

      Drekinmannequin
      Mannequin
    3. vadmium commented on Aug 4, 2015

      @vadmium
      Member

      Results of experimenting on 3.6:

      • The startup messages are written to standard error.
      • The interactive interpreter prompts to the original standard error if Readline not used. But with Gnu Readline, prompts do go to the original standard output, as does other interactive Readline output (echoed input etc). This is what Albert reported.
      • The interactive interpreter always reads from the original standard input, whether Readline is used or not.
      • The displayhook() function always writes to the current sys.stdout, as documented.
      • The excepthook() function always writes to the current sys.stderr, also as documented.
      • The input() function is documented to prompt to sys.stdout, however see bpo-1927 for some quirks with that.
      • The input() function always reads from the current sys.stdin. The Readline library is only used if sys.stdin and sys.stdout are the original file descriptors.

      I agree it would probably be more consistent for the interpreter prompt to go to standard output. It looks like stdout is inspected to determine whether Readline will be used, while stderr is not inspected. So it makes sense for the prompt to go to stdout.

      However I disagree that it should go to a redirected stream, sys.stderr or sys.stdout, since sys.stdin does not affect input. But see bpo-17620, about redirecting sys.stdin.

    4. vadmium commented on Nov 22, 2015

      @vadmium
      Member

      Actually bpo-1927 has a simple patch which should change this to stdout. I haven’t tested, the code looks like that patch will not use a redirected sys.stdout, so it would match not using a redirected sys.stdin.

    5. Drekin commented on Nov 22, 2015

      Drekinmannequin
      Mannequin
      • The interactive interpreter always reads from the original standard input, whether Readline is used or not.

      This is not true – the interactive interpreter reads via PyOS_Readline, which may call whatever readline hook is installed.

      I think the situation would be much more clear if something like my proposal was implemented (https://mail.python.org/pipermail/python-dev/2015-November/142246.html).

    6. vadmium commented on Jan 19, 2016

      @vadmium
      Member

      Adam: My experiments were assuming that PyOS_Readline() only ever uses the basic implementation or the Readline library, in order to see if there was any consistency with how Python worked in common situations.

      There is actually a test that waits for the interpreter prompt on stderr; see test_cmd_line_script.CmdLineTest.interactive_python(). I realized that changing this would have to be considered carefully, because it could easily break other code as well. It certainly should not be done in a bug fix release.

      Anyway I am proposing a patch in bpo-1927 to fix PyOS_StdioReadline(), so closing this as a duplicate.

    7. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      and removed on Jan 19, 2016
    8. transferred this issue fromon Apr 10, 2022
    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

      interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions