According to pep-0585 for the latest versions of Python, it appears we can use List and list interchangeably for type declarations. So which should I use?
Assume:
from typing import List
def hello_world_1(animals: list[str]) -> list[str]:
return animals
def hello_world_2(animals: List[str]) -> List[str]:
return animals
How can I set up a python linter to enforce consistency and only allow either upper or lowercase List for example?
According to the current Python docs, typing.List and similar are deprecated.
The docs further state
The deprecated types will be removed from the typing module in the first Python version released 5 years after the release of Python 3.9.0. See details in PEP 585—Type Hinting Generics In Standard Collections.
Concerning enforcing consistency, it says
It is expected that type checkers will flag the deprecated types when the checked program targets Python 3.9 or newer.
However, I use Pylint personally (not a type checker, admittedly) and I don't believe I've noticed it flagging the deprecated types yet.
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