Skip to content

Can't call get on an empty dict #17684

Open
@0e4ef622

Description

@0e4ef622

Bug Report

Mypy complains when I try to call get on an empty dict.

To Reproduce

x = {}.get("x")

Expected Behavior

No error.

Actual Behavior

a.py:1: error: No overload variant of "get" of "dict" matches argument type "str"  [call-overload]
a.py:1: note: Possible overload variants:
a.py:1: note:     def get(self, Never, /) -> None
a.py:1: note:     def get(self, Never, Never, /) -> Never
a.py:1: note:     def [_T] get(self, Never, _T, /) -> _T
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.11.1
  • Python version used: 3.12.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions