Skip to content

Type of conditional expression is object #8074

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions