Skip to content

Commit

Permalink
Improve type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre0512 committed Jul 23, 2023
1 parent 454f2d8 commit e6c796e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions pyhon/appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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
Expand All @@ -20,6 +20,8 @@

_LOGGER = logging.getLogger(__name__)

T = TypeVar('T')


# pylint: disable=too-many-public-methods,too-many-instance-attributes
class HonAppliance:
Expand Down Expand Up @@ -69,7 +71,15 @@ def __getitem__(self, item: str) -> Any:
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):
Expand Down
Empty file added pyhon/py.typed
Empty file.

0 comments on commit e6c796e

Please sign in to comment.