Skip to content

Commit 59ec6f9

Browse files
authored
Made setuptools.package_index.Credential a NamedTuple (#4585)
1 parent 5c829ac commit 59ec6f9

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

newsfragments/4585.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Made ``setuptools.package_index.Credential`` a `typing.NamedTuple` -- by :user:`Avasam`

setuptools/package_index.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import urllib.request
1919
from fnmatch import translate
2020
from functools import wraps
21+
from typing import NamedTuple
2122

2223
from more_itertools import unique_everseen
2324

@@ -1001,21 +1002,20 @@ def _encode_auth(auth):
10011002
return encoded.replace('\n', '')
10021003

10031004

1004-
class Credential:
1005-
"""
1006-
A username/password pair. Use like a namedtuple.
1005+
class Credential(NamedTuple):
10071006
"""
1007+
A username/password pair.
10081008
1009-
def __init__(self, username, password):
1010-
self.username = username
1011-
self.password = password
1009+
Displayed separated by `:`.
1010+
>>> str(Credential('username', 'password'))
1011+
'username:password'
1012+
"""
10121013

1013-
def __iter__(self):
1014-
yield self.username
1015-
yield self.password
1014+
username: str
1015+
password: str
10161016

1017-
def __str__(self):
1018-
return '%(username)s:%(password)s' % vars(self)
1017+
def __str__(self) -> str:
1018+
return f'{self.username}:{self.password}'
10191019

10201020

10211021
class PyPIConfig(configparser.RawConfigParser):

0 commit comments

Comments
 (0)