Merge simple type annotations from typeshed#4504
Conversation
| def __init__( | ||
| self, name: str, sources: list[str], *args, py_limited_api: bool = False, **kw | ||
| ): |
There was a problem hiding this comment.
From @abravalheri https://github.com/pypa/setuptools/pull/4505/files#r1709465928
Jason might have added support for
PathLikesources recently in pypa/distutils#237 (v72.2.0/setuptools/_distutils/extension.py#L29).(PS.: granted they are incompatible with
SETUPTOOLS_USE_DISTUTILS=stdlibbut that is a deprecated code path).
setuptools/build_meta.py
Outdated
|
|
||
| class _BuildMetaBackend(_ConfigSettingsTranslator): | ||
| def _get_build_requires(self, config_settings, requirements): | ||
| def _get_build_requires(self, config_settings: _ConfigSettings, requirements): |
There was a problem hiding this comment.
It is likely here that requirements and the return value are both list[str]. Not sure how the type-checking would react to that though...
There was a problem hiding this comment.
Doesn't cause any issue. I didn't add annotations to _get_build_requires because it's not typed in typeshed. config_settings param being typed is incidental to adding all _ConfigSettings.
But since you're mentioning it here and it's not an issue, I've added the type annotation to requirements param
|
@abravalheri I'll answer a couple comments at once:
|
setuptools/discovery.py
Outdated
| from setuptools import Distribution | ||
| from typing_extensions import TypeAlias | ||
|
|
||
| StrIter: TypeAlias = Iterator[str] |
There was a problem hiding this comment.
I don't feel like this alias brings anything of value:
- It doesn't work around any runtime issue
- It doesn't abstract away any complexity
- It's not clearer than the type it's aliasing, or doesn't help explain it
- It's barely any more concise (because it's using a shorthand instead of being clear and explicit)
In fact, it might actually hurt understandability as a dev can reasonably assume that the alias might be abstracting a more complex type and have to check what it is, rather than immediately understanding it's Iterator[str]
But it's not private. Could we maybe deprecate it ?
There was a problem hiding this comment.
I think we can be a bit bold here and replace it directly... people should not be importing StrIter from this module... A search on GitHub seems to indicate they are not: https://github.com/search?q=%2Fsetuptools.discovery.*StrIter%2F&type=code.
(the whole module should have been introduced as a private module... but at that point in time I did not know better).
8f34df1 to
f319cc5
Compare
f319cc5 to
d4143c0
Compare
9e0cc8d to
3113380
Compare
3113380 to
4eef53a
Compare
| def install_item(self, spec, download, tmpdir, deps, install_needed: bool = False): | ||
| # Installation is also needed if file in tmpdir or is not an egg | ||
| install_needed = install_needed or self.always_copy | ||
| install_needed = install_needed or bool(self.always_copy) |
There was a problem hiding this comment.
Either this, or:
- default
always_copytoFalse(I wasn't sure ifNonewas used as a special meaning "not set by user"); - allow
install_neededparam to beNone; - use a differently named variable in
install_item(like_install_needed);
…m/Avasam/setuptools into setuptools-simple-typeshed-params
|
I've added more distutils workaround so that this can be merged w/o #4691, but I'd ask to consider making distutils stubs available for all Python versions so that it stops being an issue. |
abravalheri
left a comment
There was a problem hiding this comment.
Thank you very much @Avasam.
I added 2 more questions, but I think we can merge the PR as it is, after we apply the rebase and test. Worst case scenario we can have follow ups.
setuptools/discovery.py
Outdated
| from setuptools import Distribution | ||
| from typing_extensions import TypeAlias | ||
|
|
||
| StrIter: TypeAlias = Iterator[str] |
There was a problem hiding this comment.
I think we can be a bit bold here and replace it directly... people should not be importing StrIter from this module... A search on GitHub seems to indicate they are not: https://github.com/search?q=%2Fsetuptools.discovery.*StrIter%2F&type=code.
(the whole module should have been introduced as a private module... but at that point in time I did not know better).
| preserve_mode: bool = True, | ||
| preserve_times: bool = True, | ||
| link: str | None = None, | ||
| level: object = 1, |
There was a problem hiding this comment.
level: object = 1,This one looks odd, but I suppose that is because it assumes either int or boolean values elsewhere.
There was a problem hiding this comment.
object can be used to mean "any parameter type" for unused params, (Typeshed has the alias _typeshed.Unused), but that might lead to LSP violations since subclasses should now support any object.
I should maybe change it to int (Unless you tell me that subclasses of these classes should not support an "optimization level" a depth level on this method)

Edit: uh that probably represent a depth level, not optimization ^^" Anyway, it's currently unused all the way down to the base Command class in distutils.
There was a problem hiding this comment.
I'll need to go fix it in typeshed first (or #4689) I'll leave it "as-is" for this PR. You can squash-merge the whole thing once green.
There was a problem hiding this comment.
Thank you @Avasam, once the CI finishes running I will squash it.
|
So there was a problem in the tests with the latest version of I bumped the hook version just to keep the ball rolling. Hopefully it will not clash in the next merge with skeleton. |
c8756df to
35e3ed4
Compare
|
Ah yes, the formatter just added merging of short multiline implicit string concatenation in preview mode (along with a few other small changes). Might be worth a standalone run on main, as to not "pollute" this PR with unrelated changes. |
WIP in #4705. |
35e3ed4 to
96453cb
Compare
|
Wooh! A big one done! |
Summary of changes
Please review and merge first: #4505DoneMerging #4581 and #4584 first will reduce changes in this PRDoneIt's important to validate this PR with mypy, let's re-enable it first and fix existing failures: #4604
Not done in this PR:
@overload: Merge overloaded method definitions from typeshed #4506AbstractSandbox's dynamically created methods: Add fake __getattribute__ to AbstractSandbox to let type-checkers know it has a bunch of dynamic methods #4708@type_check_only, and other TypedDict from typeshed: Merge TypedDicts from typeshed #4707Step 6.1 of #2345 (comment)
Pull Request Checklist
newsfragments/. (nothing user-facing as static typing users would still be usingtypes-setuptools)(See documentation for details)