diff --git a/newsfragments/4585.feature.rst b/newsfragments/4585.feature.rst new file mode 100644 index 0000000000..566bca75f8 --- /dev/null +++ b/newsfragments/4585.feature.rst @@ -0,0 +1 @@ +Made ``setuptools.package_index.Credential`` a `typing.NamedTuple` -- by :user:`Avasam` diff --git a/setuptools/package_index.py b/setuptools/package_index.py index a66cbb2e61..1510e01934 100644 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -18,6 +18,7 @@ import urllib.request from fnmatch import translate from functools import wraps +from typing import NamedTuple from more_itertools import unique_everseen @@ -1001,21 +1002,20 @@ def _encode_auth(auth): return encoded.replace('\n', '') -class Credential: - """ - A username/password pair. Use like a namedtuple. +class Credential(NamedTuple): """ + A username/password pair. - def __init__(self, username, password): - self.username = username - self.password = password + Displayed separated by `:`. + >>> str(Credential('username', 'password')) + 'username:password' + """ - def __iter__(self): - yield self.username - yield self.password + username: str + password: str - def __str__(self): - return '%(username)s:%(password)s' % vars(self) + def __str__(self) -> str: + return f'{self.username}:{self.password}' class PyPIConfig(configparser.RawConfigParser):