This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Document getpass.getpass behavior on ^C
Type: Stage: resolved
Components: Documentation Versions: Python 3.10, Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: davidism, docs@python, iritkatriel, terry.reedy, untitaker
Priority: normal Keywords:

Created on 2015-07-24 23:12 by untitaker, last changed 2022-04-11 14:58 by admin.

Messages (6)
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

    getpass.getpass('getpass: ')
print('goodbye getpass')

    input('input: ')
print('goodbye input')


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

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.
msg410824 - (view) Author: David Lord (davidism) Date: 2022-01-17 21:12
I can reproduce this on Python 3.10. 
Actually, `input` and `getpass` both seem to have this behavior now. Please reopen it.

import getpass

    getpass.getpass("in: ")


$ python
getpass: ^D done

Run this and press `Ctrl+D` or `Ctrl+C`. The shell prompt appears on the same line rather than the next line.
msg410825 - (view) Author: David Lord (davidism) Date: 2022-01-17 21:13
Meant to say that "done" shows up on the same line, not the shell prompt. An earlier version of my example was in the REPL, where its prompt *does* show up on the same line.
msg411181 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-01-21 20:31
In IDLE Shell, with either ^C or ^D,

>> try:
...     input('??')
... except:
...     'done'

'getpass.getpass('??') does same after printing warning from line 100 that fallback_getpass is being used.  The newline may be supplied by IDLE, not sure.
Date User Action Args
2022-04-11 14:58:19adminsetgithub: 68899
2022-01-21 20:31:24terry.reedysetnosy: + terry.reedy
messages: + msg411181
2022-01-17 21:15:13iritkatrielsetresolution: works for me ->
versions: + Python 3.9, Python 3.10, - Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6
2022-01-17 21:13:24davidismsetmessages: + msg410825
2022-01-17 21:13:14iritkatrielsetstatus: closed -> open
2022-01-17 21:12:08davidismsetnosy: + davidism
messages: + msg410824
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