We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
TypeVar
I have searched for a similar problem to reproduce but I haven't found anything, so:
I using a self-implemented monad which roughly looks as follows:
class Ok[T, E = None]: def __init__(self, value: T) -> None: self._value = value class Err[E, T = None]: def __init__(self, value: E) -> None: self._value = value type Result[T, E] = Ok[T, E] | Err[E, T]
Now, inference of the second TypeVar variable works as intended, apart from the ternary operator.
Actual Behavior
class[U] Bar: def foo(data: U, cond: bool) -> Result[U, str]: return Ok(data) if cond else Err("Error")
results in
Incompatible return value type (got "Ok[U, str] | Err[str, None]", expected "Ok[U, str] | Err[str, U]")
Expected Behavior
def foo[U](data: U, cond: bool) -> Result[U, str]: if cond: return Ok(data) else return Err("Error")
and
def foo[U](data: U, cond: bool) -> Result[U, str]: if cond: return Ok(data) return Err("Error")
typecheck just fine.
Your Environment
mypy.ini
[tool.mypy] check_untyped_defs = true disallow_any_unimported = true disallow_untyped_defs = true follow_imports = "normal" mypy_path = "src" namespace_packages = true no_implicit_optional = true show_error_codes = true strict_optional = true warn_no_return = true warn_redundant_casts = true warn_return_any = true warn_unused_ignores = true
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I have searched for a similar problem to reproduce but I haven't found anything, so:
I using a self-implemented monad which roughly looks as follows:
Now, inference of the second
TypeVar
variable works as intended, apart from the ternary operator.Actual Behavior
results in
Expected Behavior
and
typecheck just fine.
Your Environment
mypy 1.15.0 (compiled: yes)
none
mypy.ini
(and other config files):Python 3.13.2
The text was updated successfully, but these errors were encountered: