Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading