Skip to content

Regression: Unclear error message when using Any #19327

Open

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"

Activity

  1. hauntsaninja commented on Jun 23, 2025

    @hauntsaninja
    Collaborator

    This is probably a side effect of this typeshed change (that does reflect the runtime better): python/typeshed#13520

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