Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

getpass's echo_char should be restricted to a single ASCII character #138514

Copy link
Copy link
@bkjoh

Description

@bkjoh
Issue body actions

Bug report

Bug description:

Running getpass.getpass(echo_char="***") works until a character is entered, at which point a traceback error occurs.

import getpass
getpass.getpass(echo_char="***")
Password: Traceback (most recent call last):
  File "<python-input-10>", line 1, in <module>
    getpass.getpass(echo_char="***")
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "...\pythoncore-3.14-64\Lib\getpass.py", line 129, in win_getpass
    msvcrt.putwch(echo_char)
    ~~~~~~~~~~~~~^^^^^^^^^^^
TypeError: putwch(): argument must be a unicode character, not a string of length 3

Validation should occur upon input for this argument, and getpass should raise a ValueError stating: "'echo_char' must be a single-character ASCII string, not a string of length 3" (with ASCII only being bolded in this write-up for emphasis that a Unicode character cannot be used).

Additionally, the error message language should be revised when a non-ASCII string is entered:

import getpass
getpass.getpass(echo_char="Æ")
Traceback (most recent call last):
  File "<python-input-11>", line 1, in <module>
    getpass.getpass(echo_char="Æ")
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "...\pythoncore-3.14-64\Lib\getpass.py", line 109, in win_getpass
    _check_echo_char(echo_char)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "...\pythoncore-3.14-64\Lib\getpass.py", line 149, in _check_echo_char
    raise ValueError("'echo_char' must be a printable ASCII string, "
                     f"got: {echo_char!r}")
ValueError: 'echo_char' must be a printable ASCII string, got: 'Æ'

Better language would be: "'echo_char' must be a single-character ASCII string, got: 'Æ'".

With agreement, I can submit a pull request.

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixesbugs and security fixes3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs 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
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.