python/mypy

unexpected Incompatible types when using Union type in list

Closed this issue · 1 comments

consider a utility function:

from __future__ import annotations
from uuid import UUID

def utility_function(data: list[str | UUID] | None):
     pass

If I'm using it in this context, mypy complains:

def other_function(data: list[str]):
    utility_function(data)

raises:

error: Argument "data" to "utility_function" has incompatible type "list[str]"; expected "list[UUID | str] | None" [arg-type]
`

This kind of data dependency should be accepted no?

mypy version: 1.13.0