Pycharm: Type hint list of items

后端 未结 2 1560
旧巷少年郎
旧巷少年郎 2021-01-13 02:41

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 gues

2条回答
  •  长情又很酷
    2021-01-13 03:13

    Ł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 that type itself, which is the list type's type, doesn't support __getitem__. For list[whatever] to be valid, type would have to define a __getitem__ method, not list.

提交回复
热议问题