Skip to content

Bug with inline if-else and tuples #5649

Closed
@gregdingle

Description

@gregdingle

Thanks for all the work with mypy. I'm really enjoying it every time I code now.

I found this oddity which may be a bug.

Here is a short demo.

from typing import Tuple

def demo() -> Tuple[str, ...]:
    matches = [('a', 'b')]
    return matches[0] if matches else tuple()
    # demo.py:6: error: Incompatible return value type (got "object", expected "Tuple[str, ...]")


def noerror() -> Tuple[str, ...]:
    matches = [('a', 'b')]
    if matches:
        return matches[0]
    else:
        return tuple()

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