Skip to content

No error in function definition that returns unbound T #13061

Closed
@denballakh

Description

@denballakh
from typing import TypeVar

T = TypeVar('T')

def f() -> T: # no error
    ...

if f():
    print() # Statement is unreachable
else:
    print() # Statement is unreachable

Actual Behavior
No error in f definition. Two unreachable errors inside if f(): ... else: ...

Expected Behavior
Error in f definition. For example:

Type variable "T" is unbound
(Hint: Use "T" in function arguments to bind "T" to return type)

No errors inside if f(): ... else: ...

My Environment

  • mypy 0.961 (compiled: no)
  • no command-line flags, no config file
  • CPython 3.10.4
  • Windows 10

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions