Skip to content

UNBOUND_TYPEVAR error message should be more direct and shorter #20922

@hyperkai

Description

@hyperkai

*Notes:

The last 3 examples get the same indirect and long error messages of UNBOUND_TYPEVAR as shown below:

*Notes:

  • A parameter is a variable defined in a function header to receive an argument.
  • An argument is a value passed to a function parameter.

A function returning TypeVar should receive at least one argument containing the same TypeVar

With T for x:

def func[T](x: T) -> T:
    return x
# No error

Without T for x:

def func[T](x) -> T:
    return x
# error: A function returning TypeVar should receive at least one argument containing the same TypeVar

With no parameters:

from typing import cast

def func[T]() -> T:
    return cast(T, 'Hello')
# error: A function returning TypeVar should receive at least one argument containing the same TypeVar

With T1 for x and T2 for return type:

def func[T1, T2](x: T1) -> T2:
    return x
# error: A function returning TypeVar should receive at least one argument containing the same TypeVar

So, the same indirect and long error messages of UNBOUND_TYPEVAR should be changed:

From:

A function returning TypeVar should receive at least one argument containing the same TypeVar

To more direct and shorter one below:

A function returning TypeVar should have at least one same TypeVar parameter

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