Open
Description
Bug Report
unreachable
is raised multiple times in match-case
.
To Reproduce
from typing import Any
import re
def foo(config: dict[str, Any], section: str) -> set[str]:
"""Extract dependencies from pyproject.toml."""
try:
for key in section.split("."):
config = config[key]
except KeyError:
return NotImplemented
reveal_type(config) # dict[str,Any], should be dict[str,Any] | Any
match config:
# assume format `"package<comparator>version"`
case list() as lst: # ✘ unreachable
regex = re.compile(r"[a-zA-Z0-9_-]*") # ✘ unreachable
return {re.search(regex, dep).group() for dep in lst}
# assume format `package = "<comparator>version"`
case dict() as dct:
return set(dct.keys())
case _:
raise TypeError(f"Unexpected type: {type(config)}")
Expected Behavior
A single type: ignore[unreachable]
on line case list() as lst:
should suffice to silence both messages / there should only be a singular unreachable
error to begin with.
Actual Behavior
main.py:16: error: Subclass of "dict[str, Any]" and "list[Any]" cannot exist: would have incompatible method signatures [unreachable]
main.py:17: error: Statement is unreachable [unreachable]
Found 2 errors in 1 file (checked 1 source file)
with the added type: ignore
on line 16 it's still
main.py:17: error: Statement is unreachable [unreachable]
Found 1 error in 1 file (checked 1 source file)
EDIT: moved comment in code.