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

Type sequence checks in setuptools/dist.py #4578

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Avasam
Copy link
Contributor

@Avasam Avasam commented Aug 20, 2024

Summary of changes

Split from #4575

Fixes a TypeError when a Distribution's old included attribute was a tuple.

Note that I'm purposefully avoiding using Iterable, Sequence or Container because str matches all those. And I didn't wanna complicate the checks to allow "any iterable except str" (maybe in a future PR)

Pull Request Checklist

@Avasam Avasam force-pushed the type-setuptools-dist-sequence-methods branch 2 times, most recently from 1cabeb2 to d7db4a0 Compare August 20, 2024 17:02
@@ -799,7 +819,7 @@ def _include_misc(self, name, value):
)
else:
new = [item for item in value if item not in old]
setattr(self, name, old + new)
setattr(self, name, list(old) + new)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By adding annotations to the method, mypy now raises this issue. This fixes a TypeError when a Distribution's old included attribute was a tuple.

setuptools/dist.py Outdated Show resolved Hide resolved
@abravalheri abravalheri force-pushed the type-setuptools-dist-sequence-methods branch from d7db4a0 to daf4485 Compare August 27, 2024 10:51
due_date=(2025, 8, 28), # Originally added on 2024-08-27
)
return _sequence
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
Copy link
Contributor

Choose a reason for hiding this comment

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

@Avasam, how about this for the deprecation of sequence?

After a quick search on github, I do see people accessing it, so we cannot simply remove it...

Copy link
Contributor Author

@Avasam Avasam Aug 27, 2024

Choose a reason for hiding this comment

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

I had opted out of wanting to replacesequence by typing.Sequence in #4575 (comment) because there's a lot of implications when it comes to new checks and supported types (like having to explicitely check for str first everytime, because a str is a valid Sequence[str], both at runtime and in type-checking).
Not to say it wouldn't be an improvement, just that's not something I wanna go into for the scope of those PRs.

Is making sequence private something you want to do independent of those changes ? If so, this commit is fine yeah.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is making sequence private something you want to do independent of those changes ?

I think so. It seems to be such a trivial implementation detail, I don't know why people are importing it from setuptools.

It is probably good to deprecate it now just in case at some point we decide to remove it.

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