From e0774677ebbd36ebe16a46634a437b25a5165049 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Thu, 20 Jul 2023 23:52:07 +0200 Subject: [PATCH] Add and apply some mypy rules --- mypy.ini | 6 ++++++ pyhon/appliance.py | 17 ++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/mypy.ini b/mypy.ini index 9a76b78..0617b6b 100644 --- a/mypy.ini +++ b/mypy.ini @@ -7,3 +7,9 @@ no_implicit_optional = True warn_return_any = True show_error_codes = True warn_unused_ignores = True + +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +warn_unreachable = true \ No newline at end of file diff --git a/pyhon/appliance.py b/pyhon/appliance.py index 2b0959c..8956fc2 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -49,17 +49,20 @@ class HonAppliance: except ModuleNotFoundError: 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: if self._zone: item += f"Z{self._zone}" if "." in item: - result = self.data - 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 + return self._get_nested_item(item) if item in self.data: return self.data[item] if item in self.attributes["parameters"]: