python / python/cpython

Decide how to use `echo_char` in `getpass.fallback_getpass`

Open
#140,535 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

3.14 3.15 stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Hello everyone, I am a Chinese high school student. This is my first contribution to cpython on GitHub. If there are any errors, please kindly point them out. Thank you!
I noticed that in the getpass library of Python 3.14, there was a seemingly useless function call in fallback_getpass: _check_echo. This function was originally designed to check if the echo character is valid, but I think this call is redundant because:

  1. fallback_getpass is only called when the terminal settings cannot be controlled, and the echo_char parameter actually does not work properly at this time
    2.In a fallback scenario, even if echo_char is provided, password echo control cannot be implemented
    I suggest removing this unnecessary call. Modify the code as follows:
def fallback_getpass(prompt='Password: ', stream=None, *, echo_char=None):
    # remove the function call
    import warnings
    warnings.warn("Can not control echo on the terminal.", GetPassWarning,
                  stacklevel=2)
    if not stream:
        stream = sys.stderr
    print("Warning: Password input may be echoed.", file=stream)
    return _raw_input(prompt, stream, echo_char=echo_char)

By the way,can we make IDLE support getpass?I think it is important for the beginners!

At last,if I say something wrong, please tell me why and forgive me, thank you!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the getpass.fallback_getpass entry point and inspect how it calls _check_echo and handles echo_char when terminal settings cannot be controlled. Determine whether the validation call is needed in this fallback path, and confirm the chosen behavior with the relevant getpass behavior checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.