classification
Title: Document getpass.getpass behavior on ^C
Type: Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, iritkatriel, untitaker
Priority: normal Keywords:

Created on 2015-07-24 23:12 by untitaker, last changed 2021-01-11 19:08 by iritkatriel. This issue is now closed.

Messages (3)
msg247302 - (view) Author: Markus Unterwaditzer (untitaker) Date: 2015-07-24 23:12
getpass.getpass doesn't enter a newline when the user aborts input with ^C, while input/raw_input does.

This behavior is surprising and can lead to mis-formatting of subsequent output. However, since this behavior exists since 2.7 and applications may have started to rely on it, I'd add a note to the documentation.
msg382520 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-12-04 19:28
I don't see a difference between getpass and input in this respect:

----------------
import getpass

try:
    getpass.getpass('getpass: ')
except:
    pass
print('goodbye getpass')


try:
    input('input: ')
except:
    pass
print('goodbye input')

------------------

If I run that script and ^C after each prompt, I get this:

>python.bat x.py
Running Release|x64 interpreter...
getpass: goodbye getpass
input: goodbye input
msg384858 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-01-11 19:08
Works for me on both linux and windows.
History
Date User Action Args
2021-01-11 19:08:37iritkatrielsetstatus: pending -> closed

messages: + msg384858
stage: resolved
2020-12-04 19:28:43iritkatrielsetstatus: open -> pending

nosy: + iritkatriel
messages: + msg382520

resolution: works for me
2015-07-24 23:12:11untitakercreate