Skip to content

E3-1137: Add `mypy`

Anders Lindh Olsson requested to merge e3-1137 into master

This MR adds mypy to CI (via pre-commit). It also does some minor improvements to type hints, and then finally ignores the remaining issues.

FYI: Because of how pre-commit works - where it sets up a virtual environment - we cannot configure mypy in the standard way.

The log from mypy before the last commit:

e3/definition.py:197: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
e3/definition.py:205: error: Incompatible types in assignment (expression has type "Type[Dict[Any, Any]]", target has type "Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]")  [assignment]
e3/definition.py:206: error: Argument 1 to "deep_merge" has incompatible type "Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]"; expected "Type[Dict[Any, Any]]"  [arg-type]
e3/definition.py:207: error: Argument 2 to "deep_merge" has incompatible type "Dict[str, Dict[str, Dict[str, str]]]"; expected "Type[Dict[Any, Any]]"  [arg-type]
e3/definition.py:218: error: Value of type "Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]" is not indexable  [index]
e3/definition.py:218: error: Invalid index type "str" for "Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]"; expected type "Union[SupportsIndex, slice]"  [index]
e3/definition.py:219: error: Invalid index type "str" for "Union[str, Any, Dict[str, str]]"; expected type "Union[SupportsIndex, slice]"  [index]
e3/definition.py:220: error: Invalid index type "str" for "Union[str, Any]"; expected type "Union[SupportsIndex, slice]"  [index]
e3/definition.py:227: error: Incompatible types in assignment (expression has type "Type[Dict[Any, Any]]", variable has type "Dict[str, Dict[str, Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]]]")  [assignment]
e3/definition.py:228: error: Argument 1 to "deep_merge" has incompatible type "Dict[str, Dict[str, Dict[str, Union[str, Any]]]]"; expected "Type[Dict[Any, Any]]"  [arg-type]
e3/definition.py:229: error: Argument 2 to "deep_merge" has incompatible type "Dict[str, Dict[str, Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]]]"; expected "Type[Dict[Any, Any]]"  [arg-type]
e3/definition.py:237: error: Item "str" of "Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]" has no attribute "get"  [union-attr]
e3/definition.py:237: error: Item "int" of "Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]" has no attribute "get"  [union-attr]
e3/definition.py:237: error: Need type annotation for "module_subs"  [var-annotated]
e3/definition.py:239: error: Argument 1 to "reduce" has incompatible type "Callable[[Type[Dict[Any, Any]], Type[Dict[Any, Any]]], Type[Dict[Any, Any]]]"; expected "Callable[[Union[Dict[str, Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]], Any, str, Dict[Any, Any], Dict[str, str]], Union[Dict[str, Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]], Any, str, Dict[Any, Any], Dict[str, str]]], Union[Dict[str, Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]], Any, str, Dict[Any, Any], Dict[str, str]]]"  [arg-type]
e3/definition.py:240: error: Incompatible return value type (got "Union[Dict[str, Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]], Any, str, Dict[Any, Any], Dict[str, str]]", expected "Dict[str, Dict[str, str]]")  [return-value]
e3/definition.py:244: error: Item "str" of "Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]" has no attribute "get"  [union-attr]
e3/definition.py:244: error: Item "int" of "Union[str, int, Dict[str, str], Dict[str, Dict[str, str]]]" has no attribute "get"  [union-attr]
e3/definition.py:244: error: Incompatible return value type (got "Union[Any, str, Dict[str, str]]", expected "Dict[str, str]")  [return-value]
Found 18 errors in 1 file (checked 22 source files)

Merge request reports