Skip to content

type checking in lambdas stops working when using Iterable instead of list #20163

@Tinche

Description

@Tinche

Say we have a function like this:

from collections.abc import Callable, Iterable

def f[T](a: Callable[[T], Iterable[list[T]]]) -> None: ...

This generates no errors:

from typing import assert_never

f(lambda a: [assert_never(True)])

It would appear there's no checking in the lambda body.

However if I change the Iterable to list:

def f[T](a: Callable[[T], list[list[T]]]) -> None: ...

Then it works, and an error is shown as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-contextType context / bidirectional inference

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions