-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Merge simple type annotations from typeshed #4504
Merge simple type annotations from typeshed #4504
Conversation
setuptools/extension.py
Outdated
def __init__( | ||
self, name: str, sources: list[str], *args, py_limited_api: bool = False, **kw | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From @abravalheri https://github.com/pypa/setuptools/pull/4505/files#r1709465928
Jason might have added support for
PathLike
sources recently in pypa/distutils#237 (v72.2.0
/setuptools/_distutils/extension.py#L29).(PS.: granted they are incompatible with
SETUPTOOLS_USE_DISTUTILS=stdlib
but that is a deprecated code path).
setuptools/build_meta.py
Outdated
@@ -289,7 +297,7 @@ def _arbitrary_args(self, config_settings: _ConfigSettings) -> Iterator[str]: | |||
|
|||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
if TYPE_CHECKING: | ||
from setuptools import Distribution | ||
from typing_extensions import TypeAlias | ||
|
||
StrIter: TypeAlias = Iterator[str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
…ools-simple-typeshed-params
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either this, or:
- default
always_copy
toFalse
(I wasn't sure ifNone
was used as a special meaning "not set by user"); - allow
install_needed
param to beNone
; - use a differently named variable in
install_item
(like_install_needed
);
…m/Avasam/setuptools into setuptools-simple-typeshed-params
…ools-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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
if TYPE_CHECKING: | ||
from setuptools import Distribution | ||
from typing_extensions import TypeAlias | ||
|
||
StrIter: TypeAlias = Iterator[str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Avasam, once the CI finishes running I will squash it.
…m/Avasam/setuptools into setuptools-simple-typeshed-params
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)