From e6c796e822bb82dc10ae58b41f23ac8f795c1e18 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sun, 23 Jul 2023 21:55:33 +0200 Subject: [PATCH] Improve type hints --- mypy.ini | 1 - pyhon/appliance.py | 14 ++++++++++++-- pyhon/py.typed | 0 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 pyhon/py.typed diff --git a/mypy.ini b/mypy.ini index 50757c9..52281b7 100644 --- a/mypy.ini +++ b/mypy.ini @@ -10,7 +10,6 @@ disallow_untyped_defs = true disable_error_code = annotation-unchecked enable_error_code = ignore-without-code, redundant-self, truthy-iterable follow_imports = silent -ignore_missing_imports = true local_partial_types = true no_implicit_optional = true no_implicit_reexport = true diff --git a/pyhon/appliance.py b/pyhon/appliance.py index 8956fc2..03c94a4 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -3,7 +3,7 @@ import logging import re from datetime import datetime, timedelta from pathlib import Path -from typing import Optional, Dict, Any, TYPE_CHECKING, List +from typing import Optional, Dict, Any, TYPE_CHECKING, List, TypeVar, overload from pyhon import diagnose, exceptions from pyhon.appliances.base import ApplianceBase @@ -20,6 +20,8 @@ if TYPE_CHECKING: _LOGGER = logging.getLogger(__name__) +T = TypeVar('T') + # pylint: disable=too-many-public-methods,too-many-instance-attributes class HonAppliance: @@ -69,7 +71,15 @@ class HonAppliance: return self.attributes["parameters"][item].value return self.info[item] - def get(self, item: str, default: Any = None) -> Any: + @overload + def get(self, item: str, default: None = None) -> Any: + ... + + @overload + def get(self, item: str, default: T) -> T: + ... + + def get(self, item: str, default: Optional[T] = None) -> Any: try: return self[item] except (KeyError, IndexError): diff --git a/pyhon/py.typed b/pyhon/py.typed new file mode 100644 index 0000000..e69de29