KEMBAR78
Type of conditional expression is object · Issue #8074 · python/mypy · GitHub
Skip to content

Type of conditional expression is object #8074

@cjolowicz

Description

@cjolowicz

The type of the following conditional expression is object:

s: str = "key=value"
a, b = s.split("=", 1) if "=" in s else ("key", "default")
# main.py:2: error: 'builtins.object' object is not iterable

It should be a union type instead, such as Union[List[str], Tuple[str, str]].

(Note that str.split returns List[str] while the else branch has the type Tuple[str, str].)

This is a follow-up to #3487.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions