def json_file_to_dict(_file: str) -> dict:
Does it mean that function returns a dictionary type? As far as I know, python is loosely typed language and it does not enforce you to specify data type of a variable.
def json_file_to_dict(_file: str) -> dict:
Does it mean that function returns a dictionary type? As far as I know, python is loosely typed language and it does not enforce you to specify data type of a variable.
These are type hints. They were introduced in Python 3.5 as part of PEP 0484.
They are essentially a contract that this function returns a dict
(and expects _file
to be an instance of str
), but they're not strictly enforced. They're also fully optional.
From the PEP:
While these annotations are available at runtime through the usual
__annotations__
attribute, no type checking happens at runtime. Instead, the proposal assumes the existence of a separate off-line type checker which users can run over their source code voluntarily. Essentially, such a type checker acts as a very powerful linter.
It's a syntax of type hints. It'll be included in Python 3.5.
For detailed description please refer to PEP0484.