8000 More stdlib updates by arihant2math · Pull Request #5737 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

More stdlib updates #5737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update getpass to 3.13.3
  • Loading branch information
arihant2math authored and youknowone committed Apr 30, 2025
commit dd40bf7566742e850e5e08276b05f345744adc5e
15 changes: 11 additions & 4 deletions Lib/getpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io
import os
import sys
import warnings

__all__ = ["getpass","getuser","GetPassWarning"]

Expand Down Expand Up @@ -118,6 +117,7 @@ def win_getpass(prompt='Password: ', stream=None):


def fallback_getpass(prompt='Password: ', stream=None):
import warnings
warnings.warn("Can not control echo on the terminal.", GetPassWarning,
stacklevel=2)
if not stream:
Expand Down Expand Up @@ -156,17 +156,24 @@ def getuser():

First try various environment variables, then the password
database. This works on Windows as long as USERNAME is set.
Any failure to find a username raises OSError.

.. versionchanged:: 3.13
Previously, various exceptions beyond just :exc:`OSError`
were raised.
"""

for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
user = os.environ.get(name)
if user:
return user

# If this fails, the exception will "explain" why
import pwd
return pwd.getpwuid(os.getuid())[0]
try:
import pwd
return pwd.getpwuid(os.getuid())[0]
except (ImportError, KeyError) as e:
raise OSError('No username set in the environment') from e


# Bind the name getpass to the appropriate function
try:
Expand Down
7 changes: 5 additions & 2 deletions Lib/test/test_getpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def test_username_priorities_of_env_values(self, environ):
environ.get.return_value = None
try:
getpass.getuser()
except ImportError: # in case there's no pwd module
except OSError: # in case there's no pwd module
pass
except KeyError:
# current user has no pwd entry
pass
self.assertEqual(
environ.get.call_args_list,
Expand All @@ -44,7 +47,7 @@ def test_username_falls_back_to_pwd(self, environ):
getpass.getuser())
getpw.assert_called_once_with(42)
else:
self.assertRaises(ImportError, getpass.getuser)
self.assertRaises(OSError, getpass.getuser)


class GetpassRawinputTest(unittest.TestCase):
Expand Down
0