Typehints for Sized Iterable in Python

前端 未结 4 2087
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-06 09:24

I have a function that uses the len function on one of it\'s parameters and iterates over the parameter. Now I can choose whether to annotate the type with

4条回答
  •  失恋的感觉
    2020-12-06 09:46

    You should go with Sequence from typing if you plan to use only list or tuple and access its elements by index, like x[0]. Sequence is both Sized and Iterable, see here.

提交回复
热议问题