Skip to content

Regression with narrowing with negative intersection #20597

@hauntsaninja

Description

@hauntsaninja
from __future__ import annotations
from typing import Any

class array: ...

def get_result() -> Any: ...

def foo(x: str | array) -> str:
    result = get_result()
    if isinstance(result, array):
        return "asdf"
    if result is x:
        reveal_type(result)  # N: Revealed type is "Any"
        return result
    raise

As of #20492 we now get 14: error: Incompatible return value type (got "str | array", expected "str")
I don't have a fix for this in my stack (and expect a fix to be tricky)

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