Skip to content

[regression] Type not narrowed after isinstance inside or expression #21225

@p-sawicki

Description

@p-sawicki

Bug Report

This seems to have regressed in ef28d9c cc @hauntsaninja. On the previous commit the revealed type is Any.

To Reproduce

from typing import Any

def f(val: Any | str) -> None:
    if val is None or isinstance(val, str):
        return
    reveal_type(val)  # Revealed type is "Any | str"

Expected Behavior

note: Revealed type is "Any"

Actual Behavior

note: Revealed type is "Any | str"

Your Environment

  • Mypy version used: mypy 2.0.0+dev.ef28d9c2ca6476a9cffeb6c1e8dbe1a9432fda90
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.13.5

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