Improve type hints
This commit is contained in:
parent
454f2d8916
commit
e6c796e822
3 changed files with 12 additions and 3 deletions
1
mypy.ini
1
mypy.ini
|
@ -10,7 +10,6 @@ disallow_untyped_defs = true
|
||||||
disable_error_code = annotation-unchecked
|
disable_error_code = annotation-unchecked
|
||||||
enable_error_code = ignore-without-code, redundant-self, truthy-iterable
|
enable_error_code = ignore-without-code, redundant-self, truthy-iterable
|
||||||
follow_imports = silent
|
follow_imports = silent
|
||||||
ignore_missing_imports = true
|
|
||||||
local_partial_types = true
|
local_partial_types = true
|
||||||
no_implicit_optional = true
|
no_implicit_optional = true
|
||||||
no_implicit_reexport = true
|
no_implicit_reexport = true
|
||||||
|
|
|
@ -3,7 +3,7 @@ import logging
|
||||||
import re
|
import re
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from pathlib import Path
|
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 import diagnose, exceptions
|
||||||
from pyhon.appliances.base import ApplianceBase
|
from pyhon.appliances.base import ApplianceBase
|
||||||
|
@ -20,6 +20,8 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
T = TypeVar('T')
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-public-methods,too-many-instance-attributes
|
# pylint: disable=too-many-public-methods,too-many-instance-attributes
|
||||||
class HonAppliance:
|
class HonAppliance:
|
||||||
|
@ -69,7 +71,15 @@ class HonAppliance:
|
||||||
return self.attributes["parameters"][item].value
|
return self.attributes["parameters"][item].value
|
||||||
return self.info[item]
|
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:
|
try:
|
||||||
return self[item]
|
return self[item]
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
|
|
0
pyhon/py.typed
Normal file
0
pyhon/py.typed
Normal file
Loading…
Reference in a new issue