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 typing.List says:
Deprecated since version 3.9:
builtins.listnow 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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With