mypy
mypy copied to clipboard
Incorrect inferred type for attribute with two partial types
Unexpected type is inferred for attribute x in this example:
class C:
def __init__(self) -> None:
if int():
self.x = None
return
self.x = []
self.x.append("x")
reveal_type(C().x) # "list[str]" -- but should be "list[str] | None"
The inferred type should be list[str] | None, or alternatively mypy could require a type annotation for x, if this is too tricky to infer.
This should be tested with and without --allow-redefinition-new, since it may make a difference.
hello , i would like to work on this issue. Could you please confirm if this issue is still open for contributions? I would be happy to start working on it.
Thank you!