Skip to content

Wrong type inferred when "not in" narrowing Any  #17841

Description

@JukkaL

The revealed type here is str | None, which doesn't make sense:

fromtypingimportAnydeff(x: Any) ->None:
ifxisnotNoneandxnotin ["x"]:
returnreveal_type(x) # "str | None"

The behavior was changed in ed0cd4a. The inferred type before this commit was Any, which seems reasonable.

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