microsoft / microsoft/pyright

False unreachable warning when matching type[X]

Open
#11,294 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

```python
class Example:
__match_args__ = ("value",)
def __init__(self, value: str) -> None:
self.value = value

def f1(subclass: type[Example]) -> None:
match Example("a"):
case subclass(value):
reveal_type(value) # N: Revealed type is "builtins.str"
case anything:
reveal_type(anything) # N: Revealed type is "__main__.Example"
```

results in a `Type analysis indicates code is unreachable (reportUnreachable)` on line 11

https://pyright-play.net/?pyrightVersion=1.1.405&pythonVersion=3.13&reportUnreachable=true&code=MYGwhgzhAECiAeYC2AHEBTAXAKGn6A%2BgUmAC7AAWBYATgOYRHQC80AFAEQBuYIArug4AaAJS58AE3QAzQgQCWAO3mkibCOhDSh0HvyzQIpGiOgBaAHzQAcgHtFWcfnwatAOj0CWu3gOzYpWWkARnU%2BACNQSAhMaFIATxR0AG0EZDR0AF1TSxt7R2cScgo4RFQMTjAOERxnZ2BIdEMIqKg2T3QapzrnGnQudF4CBKT23068AGIbWIAlfsGMCTjEpvkYDnC%2BeRBSJQg3IxoObvrG6DBFeNIKJTpanrq%2BgaGR9DZL69vFOlNoaescwWvHQyze0HW0A4RBISiIbjS5UEQA

Contributor guide

Open the contributing guide

Research direction

Reproduce the unreachable warning using the linked pyright-play example with Python 3.13 and reportUnreachable enabled. Trace pyright's pattern-matching analysis for a class pattern whose subject is matched against type[Example], then add coverage for the reported reveals. Done means the second case is not reported unreachable while both revealed types remain correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.