Improve type hints

This commit is contained in:
Andre Basche 2023-07-23 21:55:33 +02:00
parent 454f2d8916
commit e6c796e822
3 changed files with 12 additions and 3 deletions

View File

@ -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

View File

@ -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):

0
pyhon/py.typed Normal file
View File