-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[match-case] unreachable
raised multiple times instead of once.
#15866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This doesn't look like a bug to me. The first error message is correct: you cannot have |
@sobolevn I don't think the first error message is correct either to be honest. From the The point about the second error message is that it is superfluous. Having subsequent |
The issue seems to be that
We basically get told that the program can never progress from line 16 to line 17, because the case cannot occur.
We get told that this line can never be reached, in the sense that the program can never proceed from the previous line to this line. So there are two
Alternatively, |
@sobolevn In principle, it would make sense for from typing import NoReturn
def foo() -> NoReturn:
while True:
pass
def bar(x: int) -> int:
return x
y = bar(foo()) This code does not produce any errors currently (#15821). However, imo, it should produce a message like
|
@randolf-scholz, you said:
That's an incorrect assumption. You've declared the type of You can see this with a simpler example. def func(y: Any):
x: list[int]
x = y
reveal_type(x) # list[int] |
@erictraut I was describing an 'ought' rather than an 'is'. If a human looks at this code: 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 Then the logical conclusion is that if the How would you type hint the code above? One could put |
@randolf-scholz use two different variables with different types: |
Bug Report
unreachable
is raised multiple times inmatch-case
.To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&flags=strict%2Cwarn-unreachable&gist=d747fcb30a23bd50025c2ca47ed8c5cf
Expected Behavior
A single
type: ignore[unreachable]
on linecase list() as lst:
should suffice to silence both messages / there should only be a singularunreachable
error to begin with.Actual Behavior
with the added
type: ignore
on line 16 it's stillEDIT: moved comment in code.
The text was updated successfully, but these errors were encountered: