Improve __(r)or__ signatures for TypedDict classes (#10565)

This commit is contained in:
Alex Waygood
2023-08-12 18:27:35 +01:00
committed by GitHub
parent 7836c47286
commit df08fcec5f
8 changed files with 29 additions and 44 deletions

View File

@@ -900,8 +900,16 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
def keys(self) -> dict_keys[str, object]: ...
def values(self) -> dict_values[str, object]: ...
if sys.version_info >= (3, 9):
@overload
def __or__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ...
def __ior__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ...
@overload
def __or__(self, __value: dict[str, Any]) -> dict[str, object]: ...
@overload
def __ror__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ...
@overload
def __ror__(self, __value: dict[str, Any]) -> dict[str, object]: ...
# supposedly incompatible definitions of __or__ and __ior__
def __ior__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ... # type: ignore[misc]
@_final
class ForwardRef:

View File

@@ -233,8 +233,16 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
def values(self) -> dict_values[str, object]: ...
def __delitem__(self, k: Never) -> None: ...
if sys.version_info >= (3, 9):
@overload
def __or__(self, __value: Self) -> Self: ...
def __ior__(self, __value: Self) -> Self: ...
@overload
def __or__(self, __value: dict[str, Any]) -> dict[str, object]: ...
@overload
def __ror__(self, __value: Self) -> Self: ...
@overload
def __ror__(self, __value: dict[str, Any]) -> dict[str, object]: ...
# supposedly incompatible definitions of `__ior__` and `__or__`:
def __ior__(self, __value: Self) -> Self: ... # type: ignore[misc]
# TypedDict is a (non-subscriptable) special form.
TypedDict: object

View File

@@ -28,8 +28,16 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
def values(self) -> dict_values[str, object]: ...
def __delitem__(self, k: Never) -> None: ...
if sys.version_info >= (3, 9):
def __or__(self, __other: Self) -> Self: ...
def __ior__(self, __other: Self) -> Self: ...
@overload
def __or__(self, __value: Self) -> Self: ...
@overload
def __or__(self, __value: dict[str, Any]) -> dict[str, object]: ...
@overload
def __ror__(self, __value: Self) -> Self: ...
@overload
def __ror__(self, __value: dict[str, Any]) -> dict[str, object]: ...
# supposedly incompatible definitions of `__or__` and `__ior__`:
def __ior__(self, __value: Self) -> Self: ... # type: ignore[misc]
def TypedDict(typename: str, fields: dict[str, type[Any]], total: bool = ...) -> type[dict[str, Any]]: ...
@overload

View File

@@ -42,16 +42,6 @@ types.GenericAlias.__getattr__
types.GenericAlias.__mro_entries__
types.GenericAlias.__call__ # Would be complicated to fix properly, Any could silence problems. #6392
typing._SpecialForm.__mro_entries__
typing._TypedDict.__delitem__
typing._TypedDict.__ior__
typing._TypedDict.__or__
typing._TypedDict.copy
typing._TypedDict.items
typing._TypedDict.keys
typing._TypedDict.pop
typing._TypedDict.setdefault
typing._TypedDict.update
typing._TypedDict.values
weakref.ProxyType.__reversed__ # Doesn't really exist
weakref.WeakValueDictionary.update
typing_extensions\.get_original_bases

View File

@@ -134,16 +134,6 @@ unittest.case.TestCase.__init_subclass__
# Super-special typing primitives
typing\._SpecialForm.*
typing._TypedDict.__delitem__
typing._TypedDict.__ior__
typing._TypedDict.__or__
typing._TypedDict.copy
typing._TypedDict.items
typing._TypedDict.keys
typing._TypedDict.pop
typing._TypedDict.setdefault
typing._TypedDict.update
typing._TypedDict.values
typing_extensions\.Final
typing\.NamedTuple
typing\.LiteralString

View File

@@ -227,16 +227,6 @@ unittest.case.TestCase.__init_subclass__
# Super-special typing primitives
typing\._SpecialForm.*
typing._TypedDict.__delitem__
typing._TypedDict.__ior__
typing._TypedDict.__or__
typing._TypedDict.copy
typing._TypedDict.items
typing._TypedDict.keys
typing._TypedDict.pop
typing._TypedDict.setdefault
typing._TypedDict.update
typing._TypedDict.values
typing_extensions\.Final
typing\.NamedTuple
typing\.LiteralString

View File

@@ -63,16 +63,6 @@ tkinter.Tk.split
types.CodeType.replace # stubtest thinks default values are None but None doesn't work at runtime
types.GenericAlias.__getattr__
types.GenericAlias.__call__ # Would be complicated to fix properly, Any could silence problems. #6392
typing._TypedDict.__delitem__
typing._TypedDict.__ior__
typing._TypedDict.__or__
typing._TypedDict.copy
typing._TypedDict.items
typing._TypedDict.keys
typing._TypedDict.pop
typing._TypedDict.setdefault
typing._TypedDict.update
typing._TypedDict.values
weakref.ProxyType.__reversed__ # Doesn't really exist
weakref.WeakValueDictionary.update
typing_extensions\.get_original_bases

View File

@@ -385,6 +385,7 @@ typing_extensions\.TypeVar.*
typing_extensions\.ParamSpec.*
typing(_extensions)?\.Generic
typing\.Protocol
(typing\._TypedDict\..+)?
typing_extensions\._TypedDict\..*
# Special primitives