Skip to content

Assigning a variable to the result of an untyped method removes any existing type constraints #3724

Closed
@rowillia

Description

@rowillia
from typing import Any, Optional

def foo() -> Optional[int]:
    return 42

raz: Any

def bar() -> int:
    x = foo()
    if isinstance(x, int):
        reveal_type(x)
        x = raz()
        reveal_type(x)
        x = x + 42
    return 0
$ python3.6 -m mypy --strict-optional test_optional_assign.py
test_optional_assign.py:11: error: Revealed type is 'builtins.int'
test_optional_assign.py:13: error: Revealed type is 'Union[builtins.int, builtins.None]'
test_optional_assign.py:14: error: Unsupported operand types for + ("Optional[int]" and "int")

I would have expected the revealed type at like 13 to be Any.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions