Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion python/ray/_common/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def deprecation_warning(
*,
help: Optional[str] = None,
error: Optional[Union[bool, Exception]] = None,
stacklevel: int = 2,
) -> None:
"""Warns (via the `logger` object) or throws a deprecation warning/error.

Expand All @@ -30,6 +31,9 @@ def deprecation_warning(
error: Whether or which exception to raise. If True, raise ValueError.
If False, just warn. If `error` is-a subclass of Exception,
raise that Exception.
stacklevel: The stacklevel to use for the warning message.
Use 2 to point to where this function is called, 3+ to point
further up the stack.

Raises:
ValueError: If `error=True`.
Expand All @@ -48,7 +52,8 @@ def deprecation_warning(
raise ValueError(msg)
else:
logger.warning(
"DeprecationWarning: " + msg + " This will raise an error in the future!"
"DeprecationWarning: " + msg + " This will raise an error in the future!",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and consistency with modern Python practices, consider using an f-string for string formatting instead of concatenation.

Suggested change
"DeprecationWarning: " + msg + " This will raise an error in the future!",
f"DeprecationWarning: {msg} This will raise an error in the future!",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is how the original code is written, I would modernize it to "DeprecationWarning: %s This will raise an error in the future!" and use arguments. Depends on what you prefer.

stacklevel=stacklevel,
)


Expand Down Expand Up @@ -105,6 +110,7 @@ def patched_init(*args, **kwargs):
new=new,
help=help,
error=error,
stacklevel=3,
)
return obj_init(*args, **kwargs)

Expand All @@ -123,6 +129,7 @@ def _ctor(*args, **kwargs):
new=new,
help=help,
error=error,
stacklevel=3,
)
# Call the deprecated method/function.
return obj(*args, **kwargs)
Expand Down