Skip to content
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

Made setuptools.package_index.Credential a NamedTuple #4585

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 `:`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if this line is redundant

Suggested change
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}'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered return ":".join(self) but felt explicit was better.



class PyPIConfig(configparser.RawConfigParser):
Expand Down
Loading