Changes to filename and path validation (#45529)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
4739e8a207
commit
b1c2cde40b
10 changed files with 127 additions and 19 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue