Skip to content

Regression on master: dict.get(default=None) gives 'no overload matches argument types' #11646

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

Closed
intgr opened this issue Nov 30, 2021 · 2 comments
Labels
bug mypy got something wrong

Comments

@intgr
Copy link
Contributor

intgr commented Nov 30, 2021

Bug Report

After the latest sync from typeshed (commit 4996d57, PR #11600), this valid code is highlighted as error by mypy:

def foo(vars: dict[str, str]):
    val = vars.get("fqdn", default=None)
    reveal_type(val)

Result before:

_local/dictget.py:3: note: Revealed type is "Union[builtins.str, None]"

Result after:

_local/dictget.py:2: error: No overload variant of "get" of "Mapping" matches argument types "str", "None"
_local/dictget.py:2: note: Possible overload variants:
_local/dictget.py:2: note:     def get(self, key: str) -> Optional[str]
_local/dictget.py:2: note:     def [_T] get(self, str, Union[str, _T]) -> Union[str, _T]
_local/dictget.py:3: note: Revealed type is "Any"

Your Environment

  • Mypy version used: mypy 0.920+dev.4996d571272adde83a3de2689c0147ca1be23f2c
  • Mypy command-line flags: (none)
  • Mypy configuration options from mypy.ini (and other config files): (none)
  • Python version used: 3.10.0
  • Operating system and version: macOS
@intgr intgr added the bug mypy got something wrong label Nov 30, 2021
@intgr intgr mentioned this issue Nov 30, 2021
@intgr
Copy link
Contributor Author

intgr commented Nov 30, 2021

Caused by changes to the Mapping class in mypy/typeshed/stdlib/typing.pyi

-    def get(self, key: _KT, default: _VT_co | _T) -> _VT_co | _T: ...
+    def get(self, __key: _KT, __default: _VT_co | _T) -> _VT_co | _T: ...

@intgr
Copy link
Contributor Author

intgr commented Nov 30, 2021

Doh. My bad, it dict.get() does not support keyword arguments, the original code worked because it was using QueryDict from Django. Sorry for the noise.

So I suppose this should be solved in django-stubs instead.

@intgr intgr closed this as completed Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant