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 MutableMapping.update's overloads to reflect relationship between key type and **kwargs #12456

Open
cfriedland5 opened this issue Jul 27, 2024 · 0 comments
Labels
stubs: improvement Improve/refactor existing annotations, other stubs issues

Comments

@cfriedland5
Copy link

cfriedland5 commented Jul 27, 2024

The current overloads for MutableMapping.update() allow the use of keyword arguments even if the key type isn't str. I think it's possible to put a type hint on self so that keyword arguments only pass type checking when the key type is str, like this.

    # **kwargs aren't allowed for general _KT
    @overload
    def update(self, m: SupportsKeysAndGetItem[_KT, _VT], /) -> None: ...
    @overload
    def update(self, m: Iterable[tuple[_KT, _VT]], /) -> None: ...
    # **kwargs are allowed when _KT is str
    @overload
    def update(self: MutableMapping[str, _VT], m: SupportsKeysAndGetItem[_KT, _VT], /, **kwargs: _VT) -> None: ...
    @overload
    def update(self: MutableMapping[str, _VT], m: Iterable[tuple[_KT, _VT]], /, **kwargs: _VT) -> None: ...
    @overload
    def update(self: MutableMapping[str, _VT], **kwargs: _VT) -> None: ...

See the current overloads for MutableMapping.update here:

typeshed/stdlib/typing.pyi

Lines 749 to 754 in 3db7f01

@overload
def update(self, m: SupportsKeysAndGetItem[_KT, _VT], /, **kwargs: _VT) -> None: ...
@overload
def update(self, m: Iterable[tuple[_KT, _VT]], /, **kwargs: _VT) -> None: ...
@overload
def update(self, **kwargs: _VT) -> None: ...

@AlexWaygood AlexWaygood added the stubs: improvement Improve/refactor existing annotations, other stubs issues label Jul 28, 2024
@cfriedland5 cfriedland5 changed the title Improve overloads for MutableMapping.update Improve MutableMapping.update's overloads to reflect relationship between key type and **kwargs Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: improvement Improve/refactor existing annotations, other stubs issues
Projects
None yet
Development

No branches or pull requests

2 participants