Skip to content

Issue with dictionary & lambda & get function #16148

Closed as not planned
Closed as not planned

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

Activity

  1. hauntsaninja commented on Sep 21, 2023

    @hauntsaninja
    Collaborator

    Thanks, duplicate of #16056

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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