While trying to understand how mypy is configured and works in Home Assistant I found out that when I set:
igonore_errors = false
in setup.cfg
and call:
mypy homeassistant/components/evohome/init.py
I get this list of errors:
homeassistant/components/evohome/init.py:110: error: Missing return statement
homeassistant/components/evohome/init.py:110: error: Implicit generic “Any”. Use “typing.Dict” and specify generic parameters
homeassistant/components/evohome/init.py:114: error: Argument 1 to “as_local” has incompatible type “Optional[datetime]”; expected “datetime”
homeassistant/components/evohome/init.py:135: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:182: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:182: error: Missing type parameters for generic type “Dict”
homeassistant/components/evohome/init.py:194: error: Argument 1 to “_dt_aware_to_naive” has incompatible type “Optional[datetime]”; expected “datetime”
homeassistant/components/evohome/init.py:233: error: Unsupported target for indexed assignment (“object”)
homeassistant/components/evohome/init.py:234: error: Value of type “object” is not indexable
homeassistant/components/evohome/init.py:268: error: Function is missing a return type annotation
homeassistant/components/evohome/init.py:268: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:279: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:284: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:294: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:389: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:403: error: Need type annotation for ‘temps’ (hint: “temps: Dict[, ] = …”)
homeassistant/components/evohome/init.py:425: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:438: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:441: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:458: error: Incompatible types in assignment (expression has type “None”, variable has type “Dict[Any, Any]”)
homeassistant/components/evohome/init.py:470: error: Incompatible types in assignment (expression has type “None”, variable has type “Dict[Any, Any]”)
homeassistant/components/evohome/init.py:479: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:496: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:519: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:527: error: Need type annotation for ‘_device_state_attrs’ (hint: “_device_state_attrs: Dict[, ] = …”)
homeassistant/components/evohome/init.py:529: error: Implicit generic “Any”. Use “typing.Dict” and specify generic parameters
homeassistant/components/evohome/init.py:541: error: Implicit generic “Any”. Use “typing.Dict” and specify generic parameters
homeassistant/components/evohome/init.py:545: error: Implicit generic “Any”. Use “typing.Dict” and specify generic parameters
homeassistant/components/evohome/init.py:562: error: Incompatible return value type (got “None”, expected “str”)
homeassistant/components/evohome/init.py:580: error: Incompatible return value type (got “None”, expected “str”)
homeassistant/components/evohome/init.py:585: error: Incompatible return value type (got “None”, expected “int”)
homeassistant/components/evohome/init.py:589: error: Argument 1 to “async_dispatcher_connect” has incompatible type “Optional[HomeAssistant]”; expected “HomeAssistant”
homeassistant/components/evohome/init.py:594: error: Incompatible return value type (got “None”, expected “float”)
homeassistant/components/evohome/init.py:608: error: Function is missing a type annotation for one or more arguments
homeassistant/components/evohome/init.py:611: error: Need type annotation for ‘_schedule’ (hint: “_schedule: Dict[, ] = …”)
homeassistant/components/evohome/init.py:612: error: Need type annotation for ‘_setpoints’ (hint: “_setpoints: Dict[, ] = …”)
homeassistant/components/evohome/init.py:621: error: Returning Any from function declared to return “Optional[float]”
homeassistant/components/evohome/init.py:623: error: Returning Any from function declared to return “Optional[float]”
homeassistant/components/evohome/init.py:666: error: Argument 1 to “_dt_evo_to_aware” has incompatible type “Optional[datetime]”; expected “datetime”
homeassistant/components/evohome/init.py:700: error: Unsupported operand types for >= (“datetime” and “None”)
homeassistant/components/evohome/init.py:700: note: Right operand is of type “Optional[datetime]”
Found 40 errors in 1 file (checked 1 source file)
After checking the first one I noticed that convert_until
isn’t returning a value. See here
Fix is very easy, but I’m wondering does it makes sense to search for such errors and fix them?
Maybe this could be done via CI for new PR?
Not sure if there are any performance benefits from it?
Not all functions have type annotations, so changing ignore_errors = false
isn’t an option for now.