Skip to content

Incorrect type narrowing for literal patterns #1349

@erictraut

Description

@erictraut

Summary

I just fixed a longstanding bug in pyright that ty appears to suffer from too. It's related to literal patterns in case statements. The runtime uses equality checks for literal pattern matching, but equality checks can succeed for non-overlapping types.

Consider the following:

def func(x: int):
    match x:
        case 1.0:
            reveal_type(x) # ty incorrectly reveals Never here
            print("This code is reachable")

func(1)

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions