#21695·mypy

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

Author: DaverballCreated Jul 8, 2026Updated Sep 22, 2026
Labelsbugtopic-type-form

Bug Report

When passing a single stringified 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 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

python
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