Add more type hints to helpers (#18350)

* Add type hints to helpers.entityfilter

* Add type hints to helpers.deprecation
This commit is contained in:
Ville Skyttä 2018-11-11 18:39:50 +02:00 committed by Paulus Schoutsen
parent b8c06ad019
commit 9411fca955
3 changed files with 20 additions and 16 deletions

View file

@ -1,9 +1,10 @@
"""Deprecation helpers for Home Assistant."""
import inspect
import logging
from typing import Any, Callable, Dict, Optional
def deprecated_substitute(substitute_name):
def deprecated_substitute(substitute_name: str) -> Callable[..., Callable]:
"""Help migrate properties to new names.
When a property is added to replace an older property, this decorator can
@ -11,9 +12,9 @@ def deprecated_substitute(substitute_name):
If the old property is defined, its value will be used instead, and a log
warning will be issued alerting the user of the impending change.
"""
def decorator(func):
def decorator(func: Callable) -> Callable:
"""Decorate function as deprecated."""
def func_wrapper(self):
def func_wrapper(self: Callable) -> Any:
"""Wrap for the original function."""
if hasattr(self, substitute_name):
# If this platform is still using the old property, issue
@ -28,8 +29,7 @@ def deprecated_substitute(substitute_name):
substitute_name, substitute_name, func.__name__,
inspect.getfile(self.__class__))
warnings[module_name] = True
# pylint: disable=protected-access
func._deprecated_substitute_warnings = warnings
setattr(func, '_deprecated_substitute_warnings', warnings)
# Return the old property
return getattr(self, substitute_name)
@ -38,7 +38,8 @@ def deprecated_substitute(substitute_name):
return decorator
def get_deprecated(config, new_name, old_name, default=None):
def get_deprecated(config: Dict[str, Any], new_name: str, old_name: str,
default: Optional[Any] = None) -> Optional[Any]:
"""Allow an old config name to be deprecated with a replacement.
If the new config isn't found, but the old one is, the old value is used