Changes to filename and path validation (#45529)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Joakim Sørensen 2021-01-26 15:53:21 +01:00 committed by GitHub
parent 4739e8a207
commit b1c2cde40b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 127 additions and 19 deletions

View file

@ -1,4 +1,5 @@
"""Deprecation helpers for Home Assistant."""
import functools
import inspect
import logging
from typing import Any, Callable, Dict, Optional
@ -73,3 +74,25 @@ def get_deprecated(
)
return config.get(old_name)
return config.get(new_name, default)
def deprecated_function(replacement: str) -> Callable[..., Callable]:
"""Mark function as deprecated and provide a replacement function to be used instead."""
def deprecated_decorator(func: Callable) -> Callable:
"""Decorate function as deprecated."""
@functools.wraps(func)
def deprecated_func(*args: tuple, **kwargs: Dict[str, Any]) -> Any:
"""Wrap for the original function."""
logger = logging.getLogger(func.__module__)
logger.warning(
"%s is a deprecated function. Use %s instead",
func.__name__,
replacement,
)
return func(*args, **kwargs)
return deprecated_func
return deprecated_decorator