Pycharm: Type hint list of items

后端 未结 2 1556
旧巷少年郎
旧巷少年郎 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

    According to official PEP to denote list of objects you should use typing.List, not list builtin.

    from typing import List
    
    
    class Something:
        pass
    
    
    def f(seq: List[Something]):  # no warning
        for o in seq:
            print(o)
    

    Update January 2021:

    Please note that built-in generics were implemented in Python 3.9, as described in PEP585.

提交回复
热议问题