Skip to content

Tell mypy et.al that Unset is always falsy #714

@taasan

Description

@taasan

Is your feature request related to a problem? Please describe.

mypy doesn't understand that Unset is always falsy

if api_object.neighbours:
    for x in api_object.neighbours:  # <-- mypy: error: Item "Unset" of "Union[Unset, None, List[Neighbour]]" has no attribute "__iter__" (not iterable)  [union-attr]
        do_something_with(x)

Describe the solution you'd like

I would like mypy to understand this automatically

Type annotation on Unset.__bool__() could be Literal[False] instead of bool, but typing.Literal is not available for python < 3.8.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions