Skip to content
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

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

Merged
merged 4 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion stdlib/typing_extensions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions stubs/mypy-extensions/mypy_extensions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions tests/stubtest_allowlists/py310.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions tests/stubtest_allowlists/py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions tests/stubtest_allowlists/py39.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ typing_extensions\.TypeVar.*
typing_extensions\.ParamSpec.*
typing(_extensions)?\.Generic
typing\.Protocol
(typing\._TypedDict\..+)?
typing_extensions\._TypedDict\..*

# Special primitives
Expand Down