Add and apply some mypy rules

This commit is contained in:
Andre Basche 2023-07-20 23:52:07 +02:00
parent fc60d15e60
commit e0774677eb
2 changed files with 16 additions and 7 deletions

View file

@ -7,3 +7,9 @@ no_implicit_optional = True
warn_return_any = True warn_return_any = True
show_error_codes = True show_error_codes = True
warn_unused_ignores = True warn_unused_ignores = True
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
warn_unreachable = true

View file

@ -49,17 +49,20 @@ class HonAppliance:
except ModuleNotFoundError: except ModuleNotFoundError:
self._extra = None self._extra = None
def _get_nested_item(self, item: str) -> Any:
result: List[Any] | Dict[str, Any] = self.data
for key in item.split("."):
if all(k in "0123456789" for k in key) and isinstance(result, list):
result = result[int(key)]
elif isinstance(result, dict):
result = result[key]
return result
def __getitem__(self, item: str) -> Any: def __getitem__(self, item: str) -> Any:
if self._zone: if self._zone:
item += f"Z{self._zone}" item += f"Z{self._zone}"
if "." in item: if "." in item:
result = self.data return self._get_nested_item(item)
for key in item.split("."):
if all(k in "0123456789" for k in key) and isinstance(result, list):
result = result[int(key)]
else:
result = result[key]
return result
if item in self.data: if item in self.data:
return self.data[item] return self.data[item]
if item in self.attributes["parameters"]: if item in self.attributes["parameters"]: