Type hints and consistent typing
-
Missing type hints:
Sometimes, there are type hints, e.g.,
def authenticate(
self,
base_url: str = None,
username: str = None,
password: str = None,
verify: bool = True,
) -> Tuple[str, Dict]:
It would help to better understand the code if more or better all def
s have type annotations.
-
Inconsistent types
base_url: str = None
should be
base_url: Optional[str] = None
-
Variable switching the type
def lookup_folder(project_data, folder_path):
folder_path = Path(folder_path)
Here, folder_path
is passed as a str
and then the type is switching to Path
.
I find these type switches make it sometimes hard to read and understand the code.
-
mypy
as a quality gate: If there is consistent typing, one could addmypy
coverage as aprecommit
quality gate.
Edited by Patrick Stöckle