Ng Wai Foong
Dec 7, 2020

--

Hi,

Let's say you have a list as follows:

['1', '2', '3']

It will parse it as it is if you are using the built-in pydantic list

simple_list: list = None

On the other hand, typing.List allows you to set sub-type constraint.

['1', '2', '3']

Can be parsed as [1, 2, 3] if you specify it as

simple_list: List[int] = None

each string elements inside it will be casted to integer instead.

--

--

Ng Wai Foong
Ng Wai Foong

Written by Ng Wai Foong

Senior AI Engineer@Yoozoo | Content Writer #NLP #datascience #programming #machinelearning | Linkedin: https://www.linkedin.com/in/wai-foong-ng-694619185/

No responses yet