Skip to content

Commit 08e8686

Browse files
committed
Accept suggestions
1 parent 17a5891 commit 08e8686

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

Doc/library/getpass.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
The :mod:`getpass` module provides two functions:
1818

19-
.. function:: getpass(prompt='Password: ', stream=None, *, echochar=None)
19+
.. function:: getpass(prompt='Password: ', stream=None, *, echo_char=None)
2020

2121
Prompt the user for a password without echoing. The user is prompted using
2222
the string *prompt*, which defaults to ``'Password: '``. On Unix, the
@@ -25,10 +25,10 @@ The :mod:`getpass` module provides two functions:
2525
(:file:`/dev/tty`) or if that is unavailable to ``sys.stderr`` (this
2626
argument is ignored on Windows).
2727

28-
The *echochar* argument controls how user input is displayed while typing.
29-
If *echochar* is ``None`` (default), input remains hidden. Otherwise,
30-
*echochar* must be a printable ASCII string and each typed character
31-
is replaced by the former. For example, ``echochar='*'`` will display
28+
The *echo_char* argument controls how user input is displayed while typing.
29+
If *echo_char* is ``None`` (default), input remains hidden. Otherwise,
30+
*echo_char* must be a printable ASCII string and each typed character
31+
is replaced by it. For example, ``echo_char='*'`` will display
3232
asterisks instead of the actual input.
3333

3434
If echo free input is unavailable getpass() falls back to printing
@@ -40,7 +40,7 @@ The :mod:`getpass` module provides two functions:
4040
terminal you launched IDLE from rather than the idle window itself.
4141

4242
.. versionchanged:: next
43-
Added the *echochar* parameter for keyboard feedback.
43+
Added the *echo_char* parameter for keyboard feedback.
4444

4545
.. exception:: GetPassWarning
4646

Doc/whatsnew/3.14.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ getpass
612612
-------
613613

614614
* Support keyboard feedback by :func:`getpass.getpass` via the keyword-only
615-
optional argument ``echochar``. Placeholder characters are rendered whenever
615+
optional argument ``echo_char``. Placeholder characters are rendered whenever
616616
a character is entered, and removed when a character is deleted.
617617
(Contributed by Semyon Moroz in :gh:`77065`.)
618618

Lib/getpass.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Utilities to get a password and/or the current user name.
22
3-
getpass(prompt[, stream[, echochar]]) - Prompt for a password, with echo
3+
getpass(prompt[, stream[, echo_char]]) - Prompt for a password, with echo
44
turned off and optional keyboard feedback.
55
getuser() - Get the user name from the environment or password database.
66
@@ -26,14 +26,14 @@
2626
class GetPassWarning(UserWarning): pass
2727

2828

29-
def unix_getpass(prompt='Password: ', stream=None, *, echochar=None):
29+
def unix_getpass(prompt='Password: ', stream=None, *, echo_char=None):
3030
"""Prompt for a password, with echo turned off.
3131
3232
Args:
3333
prompt: Written on stream to ask for the input. Default: 'Password: '
3434
stream: A writable file object to display the prompt. Defaults to
3535
the tty. If no tty is available defaults to sys.stderr.
36-
echochar: A string used to mask input (e.g., '*'). If None, input is
36+
echo_char: A string used to mask input (e.g., '*'). If None, input is
3737
hidden.
3838
Returns:
3939
The seKr3t input.
@@ -43,7 +43,7 @@ def unix_getpass(prompt='Password: ', stream=None, *, echochar=None):
4343
4444
Always restores terminal settings before returning.
4545
"""
46-
_check_echochar(echochar)
46+
_check_echo_char(echo_char)
4747

4848
passwd = None
4949
with contextlib.ExitStack() as stack:
@@ -73,15 +73,15 @@ def unix_getpass(prompt='Password: ', stream=None, *, echochar=None):
7373
old = termios.tcgetattr(fd) # a copy to save
7474
new = old[:]
7575
new[3] &= ~termios.ECHO # 3 == 'lflags'
76-
if echochar:
76+
if echo_char:
7777
new[3] &= ~termios.ICANON
7878
tcsetattr_flags = termios.TCSAFLUSH
7979
if hasattr(termios, 'TCSASOFT'):
8080
tcsetattr_flags |= termios.TCSASOFT
8181
try:
8282
termios.tcsetattr(fd, tcsetattr_flags, new)
8383
passwd = _raw_input(prompt, stream, input=input,
84-
echochar=echochar)
84+
echo_char=echo_char)
8585

8686
finally:
8787
termios.tcsetattr(fd, tcsetattr_flags, old)
@@ -102,11 +102,11 @@ def unix_getpass(prompt='Password: ', stream=None, *, echochar=None):
102102
return passwd
103103

104104

105-
def win_getpass(prompt='Password: ', stream=None, *, echochar=None):
105+
def win_getpass(prompt='Password: ', stream=None, *, echo_char=None):
106106
"""Prompt for password with echo off, using Windows getwch()."""
107107
if sys.stdin is not sys.__stdin__:
108108
return fallback_getpass(prompt, stream)
109-
_check_echochar(echochar)
109+
_check_echo_char(echo_char)
110110

111111
for c in prompt:
112112
msvcrt.putwch(c)
@@ -118,15 +118,15 @@ def win_getpass(prompt='Password: ', stream=None, *, echochar=None):
118118
if c == '\003':
119119
raise KeyboardInterrupt
120120
if c == '\b':
121-
if echochar and pw:
121+
if echo_char and pw:
122122
msvcrt.putch('\b')
123123
msvcrt.putch(' ')
124124
msvcrt.putch('\b')
125125
pw = pw[:-1]
126126
else:
127127
pw = pw + c
128-
if echochar:
129-
msvcrt.putwch(echochar)
128+
if echo_char:
129+
msvcrt.putwch(echo_char)
130130
msvcrt.putwch('\r')
131131
msvcrt.putwch('\n')
132132
return pw
@@ -142,14 +142,14 @@ def fallback_getpass(prompt='Password: ', stream=None):
142142
return _raw_input(prompt, stream)
143143

144144

145-
def _check_echochar(echochar):
145+
def _check_echo_char(echo_char):
146146
# ASCII excluding control characters
147-
if echochar and not (echochar.isprintable() and echochar.isascii()):
148-
raise ValueError("'echochar' must be a printable ASCII string, "
149-
f"got: {echochar!r}")
147+
if echo_char and not (echo_char.isprintable() and echo_char.isascii()):
148+
raise ValueError("'echo_char' must be a printable ASCII string, "
149+
f"got: {echo_char!r}")
150150

151151

152-
def _raw_input(prompt="", stream=None, input=None, echochar=None):
152+
def _raw_input(prompt="", stream=None, input=None, echo_char=None):
153153
# This doesn't save the string in the GNU readline history.
154154
if not stream:
155155
stream = sys.stderr
@@ -166,8 +166,8 @@ def _raw_input(prompt="", stream=None, input=None, echochar=None):
166166
stream.write(prompt)
167167
stream.flush()
168168
# NOTE: The Python C API calls flockfile() (and unlock) during readline.
169-
if echochar:
170-
return _readline_with_echochar(stream, input, echochar)
169+
if echo_char:
170+
return _readline_with_echo_char(stream, input, echo_char)
171171
line = input.readline()
172172
if not line:
173173
raise EOFError
@@ -176,7 +176,7 @@ def _raw_input(prompt="", stream=None, input=None, echochar=None):
176176
return line
177177

178178

179-
def _readline_with_echochar(stream, input, echochar):
179+
def _readline_with_echo_char(stream, input, echo_char):
180180
passwd = ""
181181
eof_pressed = False
182182
while True:
@@ -199,7 +199,7 @@ def _readline_with_echochar(stream, input, echochar):
199199
continue
200200
else:
201201
passwd += char
202-
stream.write(echochar)
202+
stream.write(echo_char)
203203
stream.flush()
204204
eof_pressed = False
205205
return passwd

Lib/test/test_getpass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ def test_echochar_replaces_input_with_asterisks(self):
172172
os_open.return_value = 3
173173
mock_input.return_value = mock_result
174174

175-
result = getpass.unix_getpass(echochar='*')
175+
result = getpass.unix_getpass(echo_char='*')
176176
mock_input.assert_called_once_with('Password: ', textio(),
177-
input=textio(), echochar='*')
177+
input=textio(), echo_char='*')
178178
self.assertEqual(result, mock_result)
179179

180180
def test_raw_input_with_echochar(self):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Add keyword-only optional argument *echochar* for :meth:`getpass.getpass`
1+
Add keyword-only optional argument *echo_char* for :meth:`getpass.getpass`
22
for optional visual keyboard feedback support. Patch by Semyon Moroz.

0 commit comments

Comments
 (0)