GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `getpass`'s `echo_char` should not affect keyboard shortcuts · Issue #138577 · python/cpython

getpass's echo_char should not affect keyboard shortcuts #138577

New issue
Copy link
New issue
Copy link
Closed
#141597
Closed
getpass's echo_char should not affect keyboard shortcuts#138577
#141597
Copy link
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@picnixz
picnixz
opened on Sep 6, 2025
Issue body actions

Bug report

Bug description:

Hitting Ctrl+U should clear the line but this is badly handled when echo_char is given:

>>> getpass.getpass()
Password: 
'bar'
>>> getpass.getpass(echo_char="*")
Password: *******
'foo\x15bar'

See #138514 (comment).

This issue stems from the fact that we switch to non-canonical mode (https://www.man7.org/linux/man-pages/man3/termios.3.html). The rationale is that in canonical mode, we only have a line-by-line feedback (so we would see the characters only when we hit ENTER, which is not really useful...)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-138577: Mention limitations of getpass.getpass(echo_char=...) #138677
  • [3.14] gh-138577: Mention Unix-specific limitations of getpass.getpass(echo_char=...) (GH-138677) #138696
  • gh-138577: Fix keyboard shortcuts in getpass with echo_char #141597

Activity

Next
  1. picnixz
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    on Sep 6, 2025
  2. yagggi commented on Sep 8, 2025

    @yagggi
    yagggi
    on Sep 8, 2025
    Contributor
    More actions

    Hi @picnixz , this seems to be a trival fix, would you mind if I give it a try?

  3. picnixz commented on Sep 8, 2025

    @picnixz
    picnixz
    on Sep 8, 2025
    MemberAuthor
    More actions

    I'm not sure this is a trivial fix actually as it's about dealing with readline capabilities. It's not just Ctrl+U that is badly handled, it's all keyboard shortcuts so this may be really tricky.

  4. yagggi commented on Sep 8, 2025

    @yagggi
    yagggi
    on Sep 8, 2025
    Contributor
    More actions

    Oh I see, yeah then it's tricky. Since ICANON is disabled, the best I can think of is simulating erasing logic from tty, but I'm not sure if it's worthy or not.

    I'm not going to try to fix this, hope there will be a better solution.

  5. picnixz commented on Sep 8, 2025

    @picnixz
    picnixz
    on Sep 8, 2025
    MemberAuthor
    More actions

    Since 3.14 is almost released, I think we should just mention this. I don't have enough time to investigate this and I don't know if we can fix it robustly.
    We support erasing a single character but we do not support erasing everything that was written via Ctrl+U. If you want, you can write a documentation for that though.

    @yagggi

  6. yagggi commented on Sep 8, 2025

    @yagggi
    yagggi
    on Sep 8, 2025
    Contributor
    More actions

    Sure! I'm working on it.

  7. picnixz commented on Sep 8, 2025

    @picnixz
    picnixz
    on Sep 8, 2025
    MemberAuthor
    More actions

    I'm actually wondering whether it was the correct way to do it. Shipping a feature that is not entirely complete makes me feel bad and this limitation may be annoying. Maybe we should instead put this feature in 3.15.

    @donbarbos How does it work on a Windows machine? do you have access to one? for instance what if I hit Ctrl+Backspace? does it work correctly? if not, we should perhaps revisit the entire feature and use a REPL-like approach if possible. Ok on Windows for 3.13.2, the normal behavior doesn't support those keyboard shortcuts (I hit Ctrl+Backspace) so maybe it's fine to have inconsistencies "everywhere"...

    >>> getpass.getpass()
    Password:
    'abc\x7fdef'

    Summary:

    • On Unix, keyboard shortcuts work with the default behavior (old). On Windows, those shortcuts don't work.
    • On Unix, keyboard shortcuts no longer work with echo_char. On Windows, I think they will still fail.
    • Should we ship 3.14 with something that has a weird behavior on Unix? for now, I asked for documentation but maybe it's just better to avoid it entirely on Unix until we can make it work consistently (whether we use echo_char or not).

    cc @hugovk

  8. picnixz
    added
    release-blocker
    on Sep 8, 2025
  9. github-project-automation
    added this to Release and Deferred blockers 🚫on Sep 8, 2025
  10. github-project-automation
    moved this to Todo in Release and Deferred blockers 🚫on Sep 8, 2025
  11. picnixz commented on Sep 8, 2025

    @picnixz
    picnixz
    on Sep 8, 2025
    MemberAuthor
    More actions

    I'm adding the release-blocker label to draw attention.

  12. yagggi commented on Sep 8, 2025

    @yagggi
    yagggi
    on Sep 8, 2025
    Contributor
    More actions

    I have similar worries, especially in my opinion, echoing astars when typing password is a rarely seen behavior on Unix command-line interfaces, it's quite normal on GUI applications though. Not sure if it's a good idea to have echo_char in standard library.

  13. 8 remaining items

  14. picnixz
    removed
    release-blocker
    on Sep 9, 2025
  15. lkollar
    added a commit that references this issue on Sep 9, 2025

    pythongh-138577: Mention Unix-specific limitations of `getpass.getpas…

    5439234
  16. CuriousLearner
    added a commit that references this issue on Nov 15, 2025

    pythongh-138577: Fix keyboard shortcuts in getpass with echo_char

    bb60653
  17. picnixz
    removed this from Release and Deferred blockers 🚫on Nov 28, 2025
  18. CuriousLearner
    added 5 commits that reference this issue on Mar 22, 2026

    Merge remote-tracking branch 'upstream/main' into fix-pythongh-138577

    2691ad9

    Merge branch 'main' of github.com:python/cpython into fix-pythongh-13…

    3e05fa3

    Merge branch 'main' into fix-pythongh-138577

    ef1efcb

    Merge branch 'fix-pythongh-138577' of github.com:CuriousLearner/cpyth…

    78b2c6a

    Merge branch 'main' of github.com:python/cpython into fix-pythongh-13…

    e1461a7
  19. vstinner
    added a commit that references this issue on Mar 30, 2026

    gh-138577: Fix keyboard shortcuts in getpass with echo_char (#141597)

    7f0c4f6
  20. vstinner
    closed this as completedin #141597on Mar 30, 2026
  21. picnixz commented on Mar 30, 2026

    @picnixz
    picnixz
    on Mar 30, 2026
    MemberAuthor
    More actions

    We decided not to backport the fix as a state machine was necessary to handle this (i.e. we needed a simple line editor for this to work). Note that this fix only affects people using the *echo_char* parameter. Default mode is unaffected (as it relies on readline) and will still not work properly.

    More precisely: to be able to use keyboard shortcuts you need to be in a feedback mode. If you have a hidden password, being able to use keyboard shortcuts won't help as you do not necessarily know where you are... so it's better to just support erasing the last character (which is already the case).

  22. maurycy
    added a commit that references this issue on Mar 30, 2026

    Merge remote-tracking branch 'upstream/main' into tachyon-ndjson-kole…

    6a0ea81
  23. clin1234
    added a commit that references this issue on Apr 16, 2026

    pythongh-138577: Fix keyboard shortcuts in getpass with echo_char (py…

    457fce1
  24. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-138577: Fix keyboard shortcuts in getpass with echo_char (py…

    71fce36
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

    3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.