How to properly function annotate / type hint a list of strings

前端 未结 2 1325
天命终不由人
天命终不由人 2021-01-05 00:24

I am trying to figure out how to properly function annotate or type hint a list of strings. For example, if I had a function like this:

def send_email(self,         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-05 00:58

    You need to import

    from typing import List
    List[str]
    

    Note the capital L.

    In python 3.9+ the lower case l also supports generics.

    You might want to consider something more specific. Why is to_adress a Str, but from_Adress is a List[Str]? Maybe a

    Adress = typing.NewType("Adress")
    

    is helpful.

提交回复
热议问题