Open
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
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
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Activity
Fix regression with narrowing and negative intersection (issue python…
James-4u commentedon Jan 20, 2026
https://github.com/python/mypy/compare/master...SmartDever02:fix-issue-20597-narrowing-negative-intersection?expand=1
@hauntsaninja how do you think of my proposal?