11from _typeshed import StrPath
22from abc import abstractmethod
3+ from binascii import Incomplete
34from collections .abc import ItemsView , Iterable , Mapping , Sequence
45from typing import Any , Literal , Protocol , TypedDict , TypeVar , overload , type_check_only
56from typing_extensions import Never , NotRequired
@@ -36,9 +37,7 @@ from .warnings import SetuptoolsDeprecationWarning as SetuptoolsDeprecationWarni
3637
3738_CommandT = TypeVar ("_CommandT" , bound = _Command )
3839_DistributionT = TypeVar ("_DistributionT" , bound = _Distribution , default = Distribution )
39- _T = TypeVar ("_T" )
4040_KT = TypeVar ("_KT" )
41- _VT = TypeVar ("_VT" )
4241_VT_co = TypeVar ("_VT_co" , covariant = True )
4342
4443__all__ = [
@@ -54,22 +53,22 @@ __all__ = [
5453
5554__version__ : str
5655
56+ # We need any Command subclass to be valid
57+ # Any: pyright would accept using covariance in __setitem__, but mypy won't let a dict be assignable to this protocol
58+ # This is unsound, but it's a quirk of setuptools' internals
5759@type_check_only
58- class _DictLike (Protocol [_KT , _VT_co ]): # type: ignore[misc] # Covariant type as parameter
59- @overload
60- def get (self , key : _KT , / ) -> _VT_co | None : ...
61- @overload
62- def get (self , key : _KT , default : _VT_co , / ) -> _VT_co : ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter
63- @overload
64- def get (self , key : _KT , default : _T , / ) -> _VT_co | _T : ...
60+ class _DictLike (Protocol [_KT , _VT_co ]):
61+ # See note about using _VT_co instead of Any
62+ def get (self , key : _KT , default : Any | None = None , / ) -> _VT_co | None : ...
6563 def items (self ) -> ItemsView [_KT , _VT_co ]: ...
6664 def keys (self ) -> Iterable [_KT ]: ...
6765 def __getitem__ (self , key : _KT , / ) -> _VT_co : ...
68- def __contains__ (self , x : Any , / ) -> bool : ...
66+ def __contains__ (self , x : object , / ) -> bool : ...
6967
7068@type_check_only
71- class _MutableDictLike (_DictLike [_KT , _VT ], Protocol ):
72- def __setitem__ (self , key : _KT , value : _VT , / ) -> None : ...
69+ class _MutableDictLike (_DictLike [_KT , _VT_co ], Protocol ):
70+ # See note about using _VT_co instead of Any
71+ def __setitem__ (self , key : _KT , value : Any , / ) -> None : ...
7372
7473@type_check_only
7574class _BuildInfo (TypedDict ):
@@ -107,9 +106,9 @@ def setup(
107106 download_url : str | None = None ,
108107 # Attributes from distutils.dist.Distribution.__init__ (except self.metadata)
109108 # These take priority over attributes from distutils.dist.Distribution.display_option_names
110- verbose = True ,
111- dry_run = False ,
112- help = False ,
109+ verbose : bool = True ,
110+ dry_run : bool = False ,
111+ help : bool = False ,
113112 cmdclass : _MutableDictLike [str , type [_Command ]] = {},
114113 command_packages : str | list [str ] | None = None ,
115114 script_name : StrPath | None = ..., # default is actually set in distutils.core.setup
@@ -123,7 +122,7 @@ def setup(
123122 ext_modules : Sequence [_Extension ] | None = None ,
124123 ext_package : str | None = None ,
125124 include_dirs : list [str ] | None = None ,
126- extra_path = None ,
125+ extra_path : Never = ..., # Deprecated
127126 scripts : list [str ] | None = None ,
128127 data_files : list [tuple [str , Sequence [str ]]] | None = None ,
129128 password : str = "" ,
@@ -149,13 +148,13 @@ def setup(
149148 setup_requires : list [str ] = [],
150149 # From Distribution._DISTUTILS_UNSUPPORTED_METADATA set in Distribution._set_metadata_defaults
151150 long_description_content_type : str | None = None ,
152- project_urls = {},
153- provides_extras = {},
154- license_expression = None ,
155- license_file = None ,
156- license_files = None ,
157- install_requires = [],
158- extras_require = {},
151+ project_urls : _DictLike [ Incomplete , Incomplete ] = {},
152+ provides_extras : _DictLike [ Incomplete , Incomplete ] = {},
153+ license_expression : str | None = None ,
154+ license_file : Never = ..., # Deprecated
155+ license_files : Iterable [ str ] | None = None ,
156+ install_requires : str | Iterable [ str ] = [],
157+ extras_require : _DictLike [ Incomplete , Incomplete ] = {},
159158 # kwargs used directly in distutils.core.setup
160159 distclass : type [_DistributionT ] = Distribution , # type: ignore[assignment] # noqa: Y011
161160 # Custom Distributions could accept more params
0 commit comments