Skip to content

Failing to concatenate fix lengths tuples if the tuple depends on a variable #8416

Closed
@knatten

Description

@knatten

I believe this is a bug. Reproduced with mypy 0.761 on Ubuntu 18.04.

In this code:

def breaks(self) -> None:
    var = True
    t = ("a","b") + (("c","d") if var else tuple())

def works(self) -> None:
    t = ("a","b") + (("c","d") if True else tuple())

The works function works fine, but the breaks function breaks with the following error:

$ mypy tuple_if.py 
tuple_if.py:3: error: No overload variant of "__add__" of "tuple" matches argument type "object"
tuple_if.py:3: note: Possible overload variants:
tuple_if.py:3: note:     def __add__(self, Tuple[str, ...]) -> Tuple[str, ...]
tuple_if.py:3: note:     def __add__(self, Tuple[Any, ...]) -> Tuple[Any, ...]
Found 1 error in 1 file (checked 1 source file)

I would expect the behaviour to be the same in both functions.

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