Skip to content

[1.20 regression] Any is incorrectly narrowed after is comparison #21134

Description

@WouldYouKindly

Hi, this started happening after I upgraded to 1.20 today.

xxx: Any=object()
deffunc() ->None:
if1isnotxxx:
returnreveal_type(xxx) # Revealed type is "Literal[1]"

This lead to the code that utilises sentinel objects breaking:

_missing: Any=object()
deffunc(
alias: str|None=_missing,
id_: UUID|None=_missing,
) ->bool:
returnaliasisnot_missingorid_isnot_missing# Non-overlapping identity check (left operand type: "UUID | None", right operand type: "str | None") [comparison-overlap]

Your Environment

  • Mypy version used: mypy 1.20.0 (compiled: yes)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): strict
  • Python version used: 3.13.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions