Skip to content

Ternary operator assignment reports type error #6757

Closed
@ghost

Description

Hi guys! I have this code:

def foo(field: Union[str, Tuple[str, ...]]) -> None:
    fields_sequence: Sequence[str] = field if isinstance(field, tuple) else (field,)
    print(fields_sequence)

That looks fine for me but mypy reports the next error:

error: Incompatible types in assignment (expression has type "object", variable has type "Sequence[str]")

Actually, there are two tuples on both ternary operator sides. I think this is a defect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions