-
Notifications
You must be signed in to change notification settings - Fork 78
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
mypy complains on "Missing return statement" #137
Comments
this is called an ‘exhaustiveness check’ and it can be achieved with mypy but requires more code than your example. a web search yields various articles about the details. also read up on typing.Never in the stdlib which has an example but a rather limited explanation: https://docs.python.org/3/library/typing.html#typing.Never |
@wbolster Interestingly, this passes?.. from result import Result, Err, Ok
def foo() -> Result[int, int]:
return Ok(1)
def bar() -> str:
result = foo()
match result:
case Ok(value):
return f"{value}"
case Err(e):
raise RuntimeError(e) |
interesting, maybe mypy inference limitation? can you try |
But this is not def foo() -> int | str: return 1
def bar() -> int:
match foo(): # <- does not work
case int(i): return i
case str(s): raise ValueError(s)
def baz() -> int:
value = foo()
match value: # <- does work
case int(i): return i
case str(s): raise ValueError(s) |
This works, def foo() -> int | str: return 1
def bar() -> int:
match x := foo():
case int(x): return x
case str(x): raise ValueError(x) |
This is actually a mypy bug: python/mypy#12998 |
Is this a known issue? What is the suggested way around this?
Running
mypy
on this results inThe text was updated successfully, but these errors were encountered: