Pycharm: Tip List Type

My question is different from the fact that I made a mistake using the type hint.

I discovered a strange hinge type in pycharm: enter image description here

Example- my own class. But I think this is less important because the IDE complains about the type listdoes not define a method __getitem__that is not true. I am wondering if this is a mistake, or I used it incorrectly.

+4
source share
2 answers

Aligning an official PEP to indicate a list of objects that you should use typing.List, not listbuiltin.

from typing import List


class Something:
    pass


def f(seq: List[Something]):  # no warning
    for o in seq:
        print(o)
+6
source

Łukasz , . , , .

list __getitem__, true, , . , type , list, __getitem__. list[whatever] type __getitem__, list.

+2

Source: https://habr.com/ru/post/1656024/


All Articles