【发布时间】:2022-12-01 18:59:44
【问题描述】:
I have some python that does this:
from typing import List, NewType
MultiList = NewType("MultiList", List[List[int]])
def myfunc():
multi: MultiList = []
# More stuff here
The code works fine, it's just my IDE (PyCharm) doesn't like the instantiation of multi to an empty list, I get this error:
"Expected type 'MultiList', got 'list[list[int]]' instead"
I mean, a MultiListisa list[list[int]], so I really don't know why it's complaining. Unless it's because the list is empty, but that doesn't make a lot of sense to me either.
It's not the end of the world, the code works just fine, I'd just like to know why it's "wrong", per se.
【问题讨论】:
标签: python python-typing