New submission from jan matejek <ja+pyt...@matejcik.cz>:

The fallback detection for `win_getpass` checks that `sys.stdin` is different 
from `sys.__stdin__`. If yes, it assumes that it's incapable of disabling echo, 
and calls `default_getpass` which reads from stdin.

If they are the same object, it assumes it's in a terminal and uses `msvcrt` to 
read characters.

I was not able to find any rationale for this check, it seems to have been 
introduced, oh wow, in 2001, to fix something IDLE-related.

Anyway, the check is trivially incorrect. It fails when such script is launched 
from `subprocess.Popen(stdin=PIPE)`, where both `sys.stdin` and `sys.__stdin__` 
are the same instance of `TextIOWrapper`. Same actually happens in MinTTY (Git 
Bash etc.) which is not a true terminal as far as I was able to find out?

It seems that a better check would be, e.g., `sys.stdin.isatty()`, which 
correctly returns `False` both in subprocesses and in MinTTY.

----------
components: Library (Lib)
messages: 398370
nosy: matejcik
priority: normal
severity: normal
status: open
title: getpass.getpass on Windows fallback detection is bad
type: behavior
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44762>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to