-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fully typed setuptools setup method #15146
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
Fully typed setuptools setup method #15146
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
srittau
left a comment
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.
Just one nit below, LGTM apart from that.
| __version__: str | ||
|
|
||
| @type_check_only | ||
| class _DictLike(Protocol[_KT, _VT_co]): # type: ignore[misc] # Covariant type as parameter |
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.
Ironically and coincidentally, this is very similar to the MappingLike protocol I just suggested in #15152. (Although we need this protocol here for now anyway, even if the former gets merged, until these definitions have made their way into all relevant type checkers.)
Co-authored-by: Sebastian Rittau <[email protected]>
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
| verbose=True, | ||
| dry_run=False, | ||
| help=False, | ||
| cmdclass: _MutableDictLike[str, type[_Command]] = {}, |
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.
Shouldn't this have been _MutableDictLike[str, type[_CommandT]]? Same on the command_obj attr.
I'm getting the following error in mypy now with types-setuptools-80.9.0.20251221:
setup.py:85:18: error: Argument "cmdclass" to "setup" has incompatible type "dict[str, type[setuptools.Command]]"; expected "_MutableDictLike[str, type[setuptools._distutils.cmd.Command]]" [arg-type]
setup.py:85:18: note: Following member(s) of "dict[str, type[Command]]" have conflicts:
setup.py:85:18: note: Expected:
setup.py:85:18: note: def __setitem__(self, str, type[Command], /) -> None
setup.py:85:18: note: Got:
setup.py:85:18: note: def __setitem__(self, str, type[Command], /) -> None
setup.py:85:18: note: Expected:
setup.py:85:18: note: @overload
setup.py:85:18: note: def get(self, str, /) -> type[Command] | None
setup.py:85:18: note: @overload
setup.py:85:18: note: def get(self, str, type[Command], /) -> type[Command]
setup.py:85:18: note: @overload
setup.py:85:18: note: def [_T] get(self, str, _T, /) -> type[Command] | _T
setup.py:85:18: note: Got:
setup.py:85:18: note: @overload
setup.py:85:18: note: def get(self, str, None = ..., /) -> type[Command] | None
setup.py:85:18: note: @overload
setup.py:85:18: note: def get(self, str, type[Command], /) -> type[Command]
setup.py:85:18: note: @overload
setup.py:85:18: note: def [_T] get(self, str, _T, /) -> type[Command] | _T
My cmdclass value wraps versioningit's get_cmdclasses() function:
https://github.com/jwodder/versioningit/blob/v3.3.0/src/versioningit/get_cmdclasses.py#L11-L13
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.
Thanks for the report, looks like a variance issue that I missed.
Any subtype of setuptools._distutils.cmd.Command should be valid, which setuptools.Command is.
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 opened #15161
Pulled directly from https://github.com/pypa/setuptools/pull/5021/files . But with an extra effort to try and use a dict-like protocol instead of a
dictas parameter.setuptools contributions have been stalling in the past year, thought I'd be done with it sooner. So I'm adding these here to for more parameters autocomplete and more flexible parameter types.