Skip to content

Commit

Permalink
Made setuptools.package_index.Credential a NamedTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Aug 20, 2024
1 parent ebddeb3 commit 2f77203
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions newsfragments/4585.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made ``setuptools.package_index.Credential`` a `typing.NamedTuple` -- by :user:`Avasam`
22 changes: 11 additions & 11 deletions setuptools/package_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2f77203

Please sign in to comment.