Skip to content

gh-149495: Fix input assuming the last character being a '\n'#149237

Open
Virv12 wants to merge 6 commits intopython:mainfrom
Virv12:fix-newline
Open

gh-149495: Fix input assuming the last character being a '\n'#149237
Virv12 wants to merge 6 commits intopython:mainfrom
Virv12:fix-newline

Conversation

@Virv12
Copy link
Copy Markdown

@Virv12 Virv12 commented May 1, 2026

Fix input assuming the last character being a '\n'

When reading from the tty python's builtin input function assumes that the last character read is a newline and proceed to strip it out leading to missing input.

Current behaviour:

$ ./python -c 'print(repr(input()))'     # press ^D three times to send EOF without a newline
abc'ab'

Expected behaviour:

$ ./python -c 'print(repr(input()))'
abc'abc'

@Virv12 Virv12 requested a review from ericsnowcurrently as a code owner May 1, 2026 15:03
@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 1, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot
Copy link
Copy Markdown

python-cla-bot Bot commented May 1, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented May 2, 2026

@StanFromIreland
Copy link
Copy Markdown
Member

Please open an issue, and add a test.

@picnixz
Copy link
Copy Markdown
Member

picnixz commented May 6, 2026

  1. Please create an issue.
  2. This is a non-trivial change. Are we totally sure that this won't be an issue?
  3. Is it standard to press ^D 3x to get an EOF without a \n? does it work for any terminal as well?
  4. Please add tests and update the documentation if necessary.
  5. What happens on WIndows where new lines are of the form \r\n can we get a trailing \r instead?

Comment thread Python/bltinmodule.c Outdated
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-05-02-09-43-45.gh-issue-149237.-dY_PV.rst Outdated
Virv12 and others added 2 commits May 7, 2026 15:13
…e-149237.-dY_PV.rst

Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Stan Ulbrych <stan@python.org>
@Virv12 Virv12 changed the title Fix input assuming the last character being a '\n' gh-149495: Fix input assuming the last character being a '\n' May 7, 2026
@Virv12
Copy link
Copy Markdown
Author

Virv12 commented May 7, 2026

  1. Please create an issue.

Done.

  1. This is a non-trivial change. Are we totally sure that this won't be an issue?

I don't see how this could be an issue, the comment already said that we wanted to remove a \n, now we are just explicitly checking that it's true.

  1. Is it standard to press ^D 3x to get an EOF without a \n? does it work for any terminal as well?

I don't know but it doesn't seem relevant to the PR.

  1. Please add tests and update the documentation if necessary.

Added test. The documentation does not need to be updated.

  1. What happens on WIndows where new lines are of the form \r\n can we get a trailing \r instead?

Both \r\n and \r were already supported and are still supoprted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants