Are you using types in Python ?
python - When/why use types from typing module for type hints - Stack Overflow
Types in Python and the use of typing library
Pycharm SQLAlchemy Plugin adds typing support for Mapped columns : Python
Videos
Python is not as statically typed language but we can specify the type of a variable.
Do you use this feature and if it's the case why and how ?
The "right" way is to use builtins when possible (e.g. dict over typing.Dict). typing.Dict is only needed if you use Python < 3.9. In older versions you couldn't use generic annotations like dict[str, Any] with builtins, you had to use Dict[str, Any]. See PEP 585
There is no big difference between typing.Dict and dict.
Just typing.Dict is actually a Generic Type, so it allows you to specify subtypes inside the brackets.
Like:
from typing import Dict
def func_1(arg_one: Dict[str, int]) -> Dict:
pass
But typing.Dict is only necessary if your Python version is under 3.9. Other wise you could do the same with regular dicts.
Example Python >= 3.9:
def func_1(arg_one: dict[str, int]) -> dict:
pass
Greetings fellow humans,
I am using types in Python which now are supported natively as type hints.
Why and when should I use the typing library.
Code example:
def division(a: int, b: int) -> float:
if b != 0:
return a/b
else:
print("Division by zero is not allowed") In the above example I am using typing hints without the typing library.