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?
When the current version of documentation for
Deprecated since version 3.9:
. 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).