Closed as not planned
Description
Running mypy --no-implicit-optional test.py
with the code below gives the error Incompatible default for argument "default" (default has type "None", argument has type "D")
from typing import Sequence, TypeVar, Union
D = TypeVar("D")
E = TypeVar("E")
def get_first(values: Sequence[E], default: D = None) -> Union[E, D]:
if len(values) == 0:
return default
else:
return values[0]
I would expect mypy doesn't emit any error. The type of default
should be resolved to None
when the function is called without the optional argument, e.g. get_first([])
, so that the return type is Union[E, None]
, which is equivalent to Optional[E]
.
I am using mypy 0.770 and python 3.7
Metadata
Metadata
Assignees
Labels
No labels