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

Conversation

Avasam
Copy link
Contributor

@Avasam Avasam commented Aug 20, 2024

Summary of changes

Docstring said "like a namedtuple", but I don't see why it can't be simplified to a NamedTuple

Contributes to #2345 and my batches of dunder typing (this was the only untyped __iter__ outside tests)

One potential difference is the repr:
'<setuptools.package_index.Credential object at 0x000001D0C827AD90>'
Credential(username='a', password='b')
(but __str__ already printed the values)

Pull Request Checklist

  • Changes have tests (added doctest for str, direct access is already tested)
  • News fragment added in newsfragments/.
    (See documentation for details)

@Avasam Avasam force-pushed the package_index.Credential-NamedTuple branch from 11ef30f to 091de43 Compare August 20, 2024 21:20
@Avasam Avasam force-pushed the package_index.Credential-NamedTuple branch from 091de43 to 2f77203 Compare August 20, 2024 21:25
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.

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 `:`.

@abravalheri
Copy link
Contributor

I like this one. We can revert if we find problems in the future.

@abravalheri abravalheri merged commit 59ec6f9 into pypa:main Aug 27, 2024
21 checks passed
@Avasam Avasam deleted the package_index.Credential-NamedTuple branch August 27, 2024 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants