Skip to content

Issue with dictionary & lambda & get function #16148

@Sanchoyzer

Description

@Sanchoyzer

Bug Report

For some reason, mypy doesn't handle working with a dictionary, a lambda function, and the get function correctly.

To Reproduce

from typing import Callable


def test_me(my_dict: dict | None = None) -> None:
    def _f(func: Callable) -> None:
        func('a')

    if my_dict is not None:
        _f(lambda x: my_dict.get(x))

Gist, Playgroud

Actual Behavior

error: Item "None" of "dict[Any, Any] | None" has no attribute "get" [union-attr]

Your Environment

  • Python 3.11.4
  • mypy 1.5.1

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