Skip to content

Invalid type error for deferred function #2299

Closed
@JukkaL

Description

@JukkaL

Mypy complains about the following program because of deferred type checking:

from typing import Union

def f(a: Union[int, str]) -> None:
    x
    a = x
    a + 1   # Error

x = 1 + 1

If x = 1 + 1 is before the function definition there is no error.

This was originally reported by @ecprice: #1748 (comment). There's additional discussion in the linked PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions