Summary
See https://play.ty.dev/092bbf5e-a753-4e30-bd29-1a80fb86304d and #2972 (comment).
from typing import reveal_type
x: list[int] = list()
y: list[int | None] = [None] * len(x) # Object of type `list[None]` is not assignable to `list[int | None]` (invalid-assignment)
y: list[int | None] = [None] # OK
def func() -> list[int | None]:
if ...:
return [None] * len(x) # Return type does not match returned value: expected `list[int | None]`, found `list[None]` (invalid-return-type)
else:
return [None] # OK
def func(x: list[int | None]):
...
func([None] * len(x)) # Argument to function `func` is incorrect: Expected `list[int | None]`, found `list[None]` (invalid-argument-type)
func(reveal_type([None])) # OK (Revealed type: `list[int | None]`)
Version
ty 0.0.21
Summary
See https://play.ty.dev/092bbf5e-a753-4e30-bd29-1a80fb86304d and #2972 (comment).
Version
ty 0.0.21