Skip to content

Conversation

@Avasam
Copy link
Collaborator

@Avasam Avasam commented Dec 18, 2025

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 dict as 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.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a 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
Copy link
Collaborator

@srittau srittau Dec 19, 2025

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.)

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@Avasam Avasam requested a review from srittau December 20, 2025 01:02
@srittau srittau merged commit 06ecffc into python:main Dec 20, 2025
48 checks passed
@Avasam Avasam deleted the Fully-typed-setuptools-setup-method branch December 20, 2025 12:39
verbose=True,
dry_run=False,
help=False,
cmdclass: _MutableDictLike[str, type[_Command]] = {},
Copy link

@bastimeyer bastimeyer Dec 21, 2025

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I opened #15161

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.

3 participants