KEMBAR78
False positive [str-format] for Union[Tuple[], Tuple[]] · Issue #7763 · python/mypy · GitHub
Skip to content

False positive [str-format] for Union[Tuple[], Tuple[]] #7763

@jolaf

Description

@jolaf

The following code:

from typing import Tuple, Union

t: Union[Tuple[str, int], Tuple[int, str]] = ('A', 5)
print("%s %s" % t)

produces the following output:

$ python3 Test.py 
A 5
$ mypy Test.py 
Test.py:4: error: Not enough arguments for format string
Found 1 error in 1 file (checked 1 source file)
$ mypy --version
mypy 0.740
$ python3 --version
Python 3.6.8

Note that t is in any case a two-member tuple, but mypy still treats it as a single value, which is clearly wrong.

If only one Tuple[] is left inside the Union[] or Union[] is removed altogether, the problem disappears.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions