RET503 false positive on exhaustive type check
- Dominant language
- Rust
- Stars
- 49.6k
- Forks
- 2.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 435
Description
### Summary
From the same codebase as https://github.com/astral-sh/ruff/issues/5474#issuecomment-2968706593 , RET503 still reports an error after an exhaustive type check. If the fix is applied, type checkers will warn/error about unreachable code.
[playground link](https://play.ruff.rs/98b1a534-fca2-4f66-859c-6be9a207f73f)
```py
import tarfile
import zipfile
type ArchiveKind = tarfile.TarFile | zipfile.ZipFile
def get_first_archive_member(archive: ArchiveKind) -> str:
if isinstance(archive, tarfile.TarFile):
return archive.getnames()[0]
elif isinstance(archive, zipfile.ZipFile):
return archive.namelist()[0]
# RET503 error
```
### Version
ruff 0.11.13 (5faf72a4d 2025-06-05) + playground
Contributor guide
Research direction
Start by reproducing the RET503 report with the linked Ruff playground example and inspect the RET503 implementation and its existing tests. The fix is done when the exhaustive TarFile/ZipFile check no longer produces a missing-return diagnostic without causing an unreachable-code warning from type checkers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100