@@ -109,11 +109,11 @@ class object:
109
109
def __getattribute__ (self , __name : str ) -> Any : ...
110
110
def __delattr__ (self , __name : str ) -> None : ...
111
111
def __sizeof__ (self ) -> int : ...
112
- def __reduce__ (self ) -> str | Tuple [Any , ...]: ...
112
+ def __reduce__ (self ) -> str | Tuple [object , ...]: ...
113
113
if sys .version_info >= (3 , 8 ):
114
- def __reduce_ex__ (self , __protocol : SupportsIndex ) -> str | Tuple [Any , ...]: ...
114
+ def __reduce_ex__ (self , __protocol : SupportsIndex ) -> str | Tuple [object , ...]: ...
115
115
else :
116
- def __reduce_ex__ (self , __protocol : int ) -> str | Tuple [Any , ...]: ...
116
+ def __reduce_ex__ (self , __protocol : int ) -> str | Tuple [object , ...]: ...
117
117
def __dir__ (self ) -> Iterable [str ]: ...
118
118
def __init_subclass__ (cls ) -> None : ...
119
119
@@ -170,7 +170,7 @@ class type(object):
170
170
def __instancecheck__ (self , __instance : Any ) -> bool : ...
171
171
def __subclasscheck__ (self , __subclass : type ) -> bool : ...
172
172
@classmethod
173
- def __prepare__ (metacls , __name : str , __bases : Tuple [type , ...], ** kwds : Any ) -> Mapping [str , Any ]: ...
173
+ def __prepare__ (metacls , __name : str , __bases : Tuple [type , ...], ** kwds : Any ) -> Mapping [str , object ]: ...
174
174
if sys .version_info >= (3 , 10 ):
175
175
def __or__ (self , __t : Any ) -> types .UnionType : ...
176
176
def __ror__ (self , __t : Any ) -> types .UnionType : ...
@@ -1013,6 +1013,7 @@ if sys.version_info >= (3, 10):
1013
1013
@overload
1014
1014
async def anext (__i : SupportsAnext [_T ], default : _VT ) -> _T | _VT : ...
1015
1015
1016
+ # TODO: `compile` has a more precise return type in reality; work on a way of expressing that?
1016
1017
if sys .version_info >= (3 , 8 ):
1017
1018
def compile (
1018
1019
source : str | bytes | AST ,
@@ -1037,18 +1038,23 @@ else:
1037
1038
1038
1039
def copyright () -> None : ...
1039
1040
def credits () -> None : ...
1040
- def delattr (__obj : Any , __name : str ) -> None : ...
1041
+ def delattr (__obj : object , __name : str ) -> None : ...
1041
1042
def dir (__o : object = ...) -> list [str ]: ...
1042
1043
@overload
1043
1044
def divmod (__x : SupportsDivMod [_T_contra , _T_co ], __y : _T_contra ) -> _T_co : ...
1044
1045
@overload
1045
1046
def divmod (__x : _T_contra , __y : SupportsRDivMod [_T_contra , _T_co ]) -> _T_co : ...
1047
+
1048
+ # The `globals` argument to `eval` has to be `dict[str, Any]` rather than `dict[str, object]` due to invariance.
1049
+ # (The `globals` argument has to be a "real dict", rather than any old mapping, unlike the `locals` argument.)
1046
1050
def eval (
1047
- __source : str | bytes | CodeType , __globals : dict [str , Any ] | None = ..., __locals : Mapping [str , Any ] | None = ...
1051
+ __source : str | bytes | CodeType , __globals : dict [str , Any ] | None = ..., __locals : Mapping [str , object ] | None = ...
1048
1052
) -> Any : ...
1053
+
1054
+ # Comment above regarding `eval` applies to `exec` as well
1049
1055
def exec (
1050
- __source : str | bytes | CodeType , __globals : dict [str , Any ] | None = ..., __locals : Mapping [str , Any ] | None = ...
1051
- ) -> Any : ...
1056
+ __source : str | bytes | CodeType , __globals : dict [str , Any ] | None = ..., __locals : Mapping [str , object ] | None = ...
1057
+ ) -> None : ...
1052
1058
def exit (code : object = ...) -> NoReturn : ...
1053
1059
1054
1060
class filter (Iterator [_T ], Generic [_T ]):
@@ -1077,14 +1083,15 @@ def hash(__obj: object) -> int: ...
1077
1083
def help (* args : Any , ** kwds : Any ) -> None : ...
1078
1084
def hex (__number : int | SupportsIndex ) -> str : ...
1079
1085
def id (__obj : object ) -> int : ...
1080
- def input (__prompt : Any = ...) -> str : ...
1086
+ def input (__prompt : object = ...) -> str : ...
1081
1087
@overload
1082
1088
def iter (__iterable : Iterable [_T ]) -> Iterator [_T ]: ...
1083
1089
@overload
1084
1090
def iter (__function : Callable [[], _T | None ], __sentinel : None ) -> Iterator [_T ]: ...
1085
1091
@overload
1086
- def iter (__function : Callable [[], _T ], __sentinel : Any ) -> Iterator [_T ]: ...
1092
+ def iter (__function : Callable [[], _T ], __sentinel : object ) -> Iterator [_T ]: ...
1087
1093
1094
+ # We need recursive types to express the type of the second argument to `isinstance` properly, hence the use of `Any`
1088
1095
if sys .version_info >= (3 , 10 ):
1089
1096
def isinstance (
1090
1097
__obj : object , __class_or_tuple : type | types .UnionType | Tuple [type | types .UnionType | Tuple [Any , ...], ...]
@@ -1334,6 +1341,9 @@ def round(number: SupportsRound[Any]) -> int: ...
1334
1341
def round (number : SupportsRound [Any ], ndigits : None ) -> int : ...
1335
1342
@overload
1336
1343
def round (number : SupportsRound [_T ], ndigits : SupportsIndex ) -> _T : ...
1344
+
1345
+ # See https://github.com/python/typeshed/pull/6292#discussion_r748875189
1346
+ # for why arg 3 of `setattr` should be annotated with `Any` and not `object`
1337
1347
def setattr (__obj : object , __name : str , __value : Any ) -> None : ...
1338
1348
@overload
1339
1349
def sorted (__iterable : Iterable [SupportsLessThanT ], * , key : None = ..., reverse : bool = ...) -> list [SupportsLessThanT ]: ...
@@ -1352,6 +1362,8 @@ else:
1352
1362
@overload
1353
1363
def sum (__iterable : Iterable [_T ], __start : _S ) -> _T | _S : ...
1354
1364
1365
+ # The argument to `vars()` has to have a `__dict__` attribute, so can't be annotated with `object`
1366
+ # (A "SupportsDunderDict" protocol doesn't work)
1355
1367
def vars (__object : Any = ...) -> dict [str , Any ]: ...
1356
1368
1357
1369
class zip (Iterator [_T_co ], Generic [_T_co ]):
@@ -1433,8 +1445,8 @@ class zip(Iterator[_T_co], Generic[_T_co]):
1433
1445
1434
1446
def __import__ (
1435
1447
name : str ,
1436
- globals : Mapping [str , Any ] | None = ...,
1437
- locals : Mapping [str , Any ] | None = ...,
1448
+ globals : Mapping [str , object ] | None = ...,
1449
+ locals : Mapping [str , object ] | None = ...,
1438
1450
fromlist : Sequence [str ] = ...,
1439
1451
level : int = ...,
1440
1452
) -> Any : ...
0 commit comments