Skip to content

Narrowing dict | Literal does not work in Mypy 1.5.0 #15860

Closed
@zroug

Description

@zroug

Bug Report

When using Mypy 1.5.0, expressions like dict | Literal[""] don't narrow correctly:

To Reproduce

from typing import Literal

x: Literal[""] | dict
y: Literal[""] | list

if x == "":
    reveal_type(x)

if y == "":
    reveal_type(y)

Mypy 1.4.1
Mypy 1.5.0

Expected Behavior

Both revealed types should be Literal[""]. (As in Mypy 1.4.1.)

Actual Behavior

Mypy 1.5.0 does not narrow the revealed type for x. y gets narrowed correctly.

Your Environment

See Playground links.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions