From e1993b4974200e8d89de097c7750a306202de7bf Mon Sep 17 00:00:00 2001 From: David Robertson Date: Fri, 6 May 2022 01:23:00 +0100 Subject: [PATCH] Fix sorteddict stubs Mypy now includes https://github.com/python/typeshed/pull/6653 which triggered ``` stubs/sortedcontainers/sorteddict.pyi:88: error: Signature of "update" incompatible with supertype "MutableMapping" [override] stubs/sortedcontainers/sorteddict.pyi:88: note: Superclass: stubs/sortedcontainers/sorteddict.pyi:88: note: @overload stubs/sortedcontainers/sorteddict.pyi:88: note: def update(self, SupportsKeysAndGetItem[_KT, _VT], **kwargs: _VT) -> None stubs/sortedcontainers/sorteddict.pyi:88: note: @overload stubs/sortedcontainers/sorteddict.pyi:88: note: def update(self, Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None stubs/sortedcontainers/sorteddict.pyi:88: note: @overload stubs/sortedcontainers/sorteddict.pyi:88: note: def update(self, **kwargs: _VT) -> None stubs/sortedcontainers/sorteddict.pyi:88: note: Subclass: stubs/sortedcontainers/sorteddict.pyi:88: note: @overload stubs/sortedcontainers/sorteddict.pyi:88: note: def update(self, Mapping[_KT, _VT], **kwargs: _VT) -> None stubs/sortedcontainers/sorteddict.pyi:88: note: @overload stubs/sortedcontainers/sorteddict.pyi:88: note: def update(self, Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None stubs/sortedcontainers/sorteddict.pyi:88: note: @overload stubs/sortedcontainers/sorteddict.pyi:88: note: def update(self, **kwargs: _VT) -> None ``` --- stubs/sortedcontainers/sorteddict.pyi | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/stubs/sortedcontainers/sorteddict.pyi b/stubs/sortedcontainers/sorteddict.pyi index 3a4f9c307685..7c399ab38d5e 100644 --- a/stubs/sortedcontainers/sorteddict.pyi +++ b/stubs/sortedcontainers/sorteddict.pyi @@ -85,12 +85,19 @@ class SortedDict(Dict[_KT, _VT]): def popitem(self, index: int = ...) -> Tuple[_KT, _VT]: ... def peekitem(self, index: int = ...) -> Tuple[_KT, _VT]: ... def setdefault(self, key: _KT, default: Optional[_VT] = ...) -> _VT: ... - @overload - def update(self, __map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... - @overload - def update(self, __iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... - @overload - def update(self, **kwargs: _VT) -> None: ... + # Mypy now reports the first overload as an error, because typeshed widened the type + # of `__map` to its internal `_typeshed.SupportsKeysAndGetItem` type in + # https://github.com/python/typeshed/pull/6653 + # Since sorteddicts don't change the signature of `update` from that of `dict`, we + # let the stubs for `update` inherit from the stubs for `dict`. (I suspect we could + # do the same for many othe methods.) We leave the stubs commented to better track + # how this file has evolved from the original stubs. + # @overload + # def update(self, __map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... + # @overload + # def update(self, __iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... + # @overload + # def update(self, **kwargs: _VT) -> None: ... def __reduce__( self, ) -> Tuple[