microsoft / microsoft/pyright

False positive unreachable when pattern matching `int` with `http.HTTPStatus`

Open
#10,235 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

**Describe the bug**

When using structural pattern matching to compare an `int` vs an `http.HTTPStatus` instance (and vice versa), pyright thinks the code is unreachable.

In the example code, pyright thinks the wildcard case is taken in both scenarios (hence the lack of output).

**Code or Screenshots**

Code sample in [pyright playground](https://pyright-play.net/?code=GYJw9gtgBAFgLnADlAlhRYRygCQCp4AKAynAIZwCuAzgFCiRRwCeiKAdgOarqbYgBTAG4CyAGwD6LRANq0AxmAAmAqAF4oAJgAM2uRAryYURSoBctKFZNlqq-EVIUaACgCUF616iJbdL-K29gQk5FTUAHQA8gDSnt5WgiLiUqwCLqYCbpbWgXZQEvEJvtR0ctRhNOq4IU7h0TH6hsYVztRFNvk62h1eSaKS0umt4dkBQQW91iV0QA)

```python
from http import HTTPStatus
from typing import reveal_type

code = 200

match code:
case HTTPStatus():
pass
case HTTPStatus.OK:
reveal_type(code)
case _:
pass

status = HTTPStatus.OK

match status:
case 200:
reveal_type(status)
case _:
pass

```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked pyright playground example and trace how pattern matching handles HTTPStatus, an int subclass, in both match directions. Confirm the expected reachability for each case, then add regression coverage and verify that the wildcard branch is not incorrectly treated as the only reachable case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.