Should I use a capital L List for type hinting in Python 3.9+?

In Python 3.9+ I can write list_of_integers: list[int], but I see senior developers using the older syntax (even in Python 3.9 and 3.10 scripts):

from typing import List

list_of_integers: List[int]

Is this superior for backwards compatibility and explicitness?

>Solution :

When the current version of documentation for typing.List says:

Deprecated since version 3.9: builtins.list now supports []. See PEP
585 and Generic Alias Type.

It should be considered best practice unless you have a compelling reason not to use it (like what you said about backward compatibility for older versions of Python).

Leave a Reply