Closed
Description
Running mypy --strict-optional
on the following code:
from typing import Optional, Sequence
def f(timestamps: Optional[Sequence[float]] = None):
if timestamps is None:
timestamps = [0]
reveal_type(timestamps)
def index(i: int) -> float:
return timestamps[i]
return index(0)
fails with
test.py:7: error: Revealed type is 'typing.Sequence[builtins.float]'
test.py:9: error: Value of type "Optional[Sequence[float]]" is not indexable
This is pretty weird -- MyPy knows that timestamps
isn't None
at that point, but complains in the nested function.
Metadata
Metadata
Assignees
Labels
No labels