Skip to content

Regression: Unclear error message when using Any #19327

Open
@bzoracler

Description

@bzoracler

Bug Report

See mypy Playground.

In mypy 1.15 and below, attempting to use Any as an actual type (with instances) gives an unambiguous reason for why it's not valid:

from typing import Any

def get_obj[T](t: type[T], /) -> T: ...

a: int = get_obj(Any)  # E: Argument 1 to "get_obj" has incompatible type "<typing special form>"; expected "type[Never]"  [arg-type]

In mypy 1.16 this is no longer clear:

a: int = get_obj(Any)  # E: Incompatible types in assignment (expression has type "Any", variable has type "int")  [assignment]

It looks like mypy now thinks you can create actual instances of typing.Any.

reveal_type(get_obj(Any))  # N: Revealed type is "typing.Any"

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