Skip to content

Use any and all to make collection non-optional #4573

Closed
@ilevkivskyi

Description

@ilevkivskyi

I have seen patterns like this several times:

def func() -> Optional[int]:
    pass

def test() -> List[int]:
    vals: Iterable[Optional[int]] = [func() for _ in some_list]
    if all(vals):
        return list(vals)  # None can't be in 'vals' here.
    return []

It would be convenient if binder could understand this for covariant collections.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions