Skip to content

Partial type that is "initialised" via assignment is only temporarily narrowed by isinstance #18238

Open
@tyralla

Description

@tyralla

In the following example, the last revealed type could/should be Union[builtins.int, None]:

def f() -> bool: 
    return True

u: int | tuple[int]
x = None
if f():
    x = u
    if isinstance(x, tuple):
        x = x[0]
    reveal_type(x)  # note: "builtins.int"
reveal_type(x)  # note: Revealed type is "Union[builtins.int, Tuple[builtins.int], None]"

See this comment for background information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-narrowingConditional type narrowing / binder

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions