Deprecation warning enhancement (#1738)

This commit is contained in:
Elijah Ahianyo 2023-09-06 17:46:44 +00:00 committed by GitHub
parent dd03a277cf
commit 141d1c3aab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -36,7 +36,12 @@ def route(
Returns:
The decorated function.
"""
deprecate("@rx.route is deprecated and is being replaced by @rx.page instead")
deprecate(
feature_name="@rx.route",
deprecation_version="0.2.3",
reason="and is being replaced by @rx.page due to enhanced routing features.",
removal_version="0.2.8",
)
return page(
route=route,

View File

@ -102,13 +102,27 @@ def warn(msg: str, **kwargs):
print(f"[orange1]Warning: {msg}[/orange1]", **kwargs)
def deprecate(msg: str, **kwargs):
# def deprecate(msg: str, **kwargs):
def deprecate(
feature_name: str,
reason: str,
deprecation_version: str,
removal_version: str,
**kwargs,
):
"""Print a deprecation warning.
Args:
msg: The deprecation message.
feature_name: The feature to deprecate.
reason: The reason for deprecation.
deprecation_version: The version the feature was deprecated
removal_version: The version the deprecated feature will be removed.
kwargs: Keyword arguments to pass to the print function.
"""
msg = (
f"{feature_name} has been deprecated in version {deprecation_version} {reason}. It will be completely "
f"removed in {removal_version}"
)
if LOG_LEVEL <= LogLevel.WARNING:
print(f"[yellow]DeprecationWarning: {msg}[/yellow]", **kwargs)