Open
Description
Found while playing around with attrs (now in the typeshed) and using --strict-optional
:
$ mypy --version
mypy 0.570-dev-f3491a320ffa36e6574c4370489d9f4819d7fa83 (master)
$ python --version
Python 3.6.3
# Run with --strict-optional
from typing import TypeVar, Callable, Optional, List
_T = TypeVar('_T')
def make(typ: Callable[[], _T]) -> _T:
...
def accept(arg: Optional[_T]) -> _T:
...
accept(make(list))
accept(None)
foo = accept(make(list)) # This works
bar: List[str] = accept(make(list)) # Argument 1 to "accept" has incompatible type "List[_T]"; expected "Optional[List[str]]"
Note: The real code has more arguments and an overload that handles the None case but I cut it down to the shortest repro.
The attrs version of this code is:
import attr
x: List[str] = attr.ib(attr.Factory(list))
Metadata
Metadata
Assignees
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
ilevkivskyi commentedon Feb 9, 2018
I think this is another manifestation (if not a duplicate) of #1317