-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotations
Description
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.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotations