Skip to content

Constraint solver regression in mypy 1.7.1 #16582

Closed
@erictraut

Description

@erictraut

Mypy 1.6.1 didn't produce any errors in this code, but 1.7.0 does.

Link to mypy playground

from typing import Callable, Generic, TypeVar

A = TypeVar("A")
B = TypeVar("B")

class Gen(Generic[A]): ...

def id_(x: A) -> A:
    raise NotImplementedError()

def bstep(
    x: Gen[A],
    y: A,
) -> Gen[Gen[A]]:
    raise NotImplementedError()

def bfn(
    x: Gen[Gen[A]],
) -> Gen[A]:
    return bfn_generic(x, id_, bstep) # False positive error here

def bfn_generic(
    x: Gen[A],
    id_: Callable[[B], B],
    step: Callable[[A, B], Gen[A]],
) -> A:
    raise NotImplementedError()

Note that pyright has a similar bug in its constraint solver, which is how I became aware of this issue. Here's the original pyright bug report.

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