Open MaxG87 opened 4 years ago
The first case is too difficult for mypy to figure out. It may be feasible to fix the false positive in the second case.
I guess this would also be too difficult for mypy to figure out?
def promote_optional(tup: Tuple[Optional[_T], Optional[_U]]) -> Optional[Tuple[_T, _U]]:
if None in tup:
return None
return tup
Are you reporting a bug, or opening a feature request? kind of both
Please insert below the code you are checking with mypy,
_T = TypeVar("_T") _U = TypeVar("_U")
def promote_optional(tup: Tuple[Optional[_T], Optional[_U]]) -> Optional[Tuple[_T, _U]]: for val in tup: if val is None: return None return tup
def promote_optional2(tup: Tuple[Optional[_T], Optional[_U]]) -> Optional[Tuple[_T, _U]]: if tup[0] is None: return None if tup[1] is None: return None return tup
/tmp/mwe.py:11: error: Incompatible return value type (got "Tuple[Optional[_T], Optional[_U]]", expected "Optional[Tuple[_T, _U]]") /tmp/mwe.py:19: error: Incompatible return value type (got "Tuple[Optional[_T], Optional[_U]]", expected "Optional[Tuple[_T, _U]]") Found 2 errors in 1 file (checked 1 source file)