Skip to content

Error message for TypeForm arguments with a single unresolvable forward reference is misleading #21695

Description

@Daverball

Bug Report

When passing a single strategized type expression to a function accepting a TypeForm argument, which cannot be fully resolved, due to e.g. a missing import, we get an arg-type error of the form:

Instead of an error, telling us why the type expression is invalid.

To Reproduce
https://mypy-play.net/?mypy=master&python=3.14&gist=891447236311046360886ba63c1fac83

from typing_extensions import TypeForm

def foo[T](x: TypeForm[T]) -> None:
    pass

foo("Unresolvable")

Expected Behavior

mypy should emit a name-error for Unresolvable, since it was never defined. The given example is probably the most controversial case though, since someone may actually accidentally be passing an invalid string literal, but the same thing happens for less controversial cases like "list[Unresolvable]". But I think either way it makes more sense to treat the given string literal as a type expression and emit the same errors you would emit if you saw the same string literal in an annotation.

Actual Behavior

error: Argument 1 to "foo" has incompatible type "str"; expected "TypeForm[Never]"  [arg-type]

This error does not help us solve the problem in our code at all.

Your Environment

  • Mypy version used: 2.2
  • Python version used: 3.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions