My question is different because I made a mistake using type hint.
I found a weird type hinging in pycharm:
Example
is my own class. But I guess this is less important because the IDE is complaining about list
type does not define __getitem__
method which is no true. I'm wondering if it's a bug or I used it in a wrong way.
Łukasz explained how to correct your code. I'll explain why the error message says what it does.
list
defines__getitem__
, true, but that isn't what the error message is complaining about. The error message is saying thattype
itself, which is thelist
type's type, doesn't support__getitem__
. Forlist[whatever]
to be valid,type
would have to define a__getitem__
method, notlist
.Accoring to official PEP to denote list of objects you should use
typing.List
, notlist
builtin.