[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygonzone add multiple anchors support #910

Prev Previous commit
Next Next commit
pre-commit
pre-commit
  • Loading branch information
LeviVasconcelos committed Feb 26, 2024
commit 8b443d1b45aa8ae843693c1410e21e982692927a
44 changes: 26 additions & 18 deletions supervision/utils/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@


def deprecated_parameter(
old_parameter: str,
new_parameter: str,
map_function: Callable = lambda x: x,
warn_message: str = "Warning: '{old_parameter}' in '{function_name}' is deprecated: " \
"use '{new_parameter}' instead.",
**message_kwargs
old_parameter: str,
new_parameter: str,
map_function: Callable = lambda x: x,
warn_message: str = "Warning: '{old_parameter}' in '{function_name}' "
onuralpszr marked this conversation as resolved.
Show resolved Hide resolved
"is deprecated: use '{new_parameter}' instead.",
**message_kwargs,
):
"""
A decorator to mark a function's parameter as deprecated and issue a warning when used.
A decorator to mark a function's parameter as deprecated
and issue a warning when used.

Parameters:
- old_parameter (str): The name of the deprecated parameter.
- new_parameter (str): The name of the parameter that should be used instead.
- map_function (Callable, optional): A function used to map the value of the old parameter to the new parameter.
Defaults to the identity function.
- warn_message (str, optional): The warning message to be displayed when the deprecated parameter is used.
Defaults to a generic warning message with placeholders for the old parameter, new parameter, and function name.
- **message_kwargs: Additional keyword arguments that can be used to customize the warning message.
- map_function (Callable, optional): A function used to map the value of the old
parameter to the new parameter. Defaults to the identity function.
- warn_message (str, optional): The warning message to be displayed when the
deprecated parameter is used. Defaults to a generic warning message with
placeholders for the old parameter, new parameter, and function name.
- **message_kwargs: Additional keyword arguments that can be used to customize
the warning message.

Returns:
Callable: A decorator function that can be applied to mark a function's parameter as deprecated.
Callable: A decorator function that can be applied to mark a function's
parameter as deprecated.

Usage Example:
```python
Expand All @@ -35,8 +39,10 @@ def example_function(new_param):
# When calling the function with the deprecated parameter:
example_function(old_param="deprecated_value")
```
This will trigger a deprecation warning and execute the function with the mapped value of the deprecated parameter.
This will trigger a deprecation warning and execute the function with the mapped
value of the deprecated parameter.
"""

def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
Expand All @@ -50,10 +56,12 @@ def wrapper(*args, **kwargs):

# Display deprecation warning
warnings.warn(
message=warn_message.format(function_name=function_name,
old_parameter=old_parameter,
new_parameter=new_parameter,
**message_kwargs),
message=warn_message.format(
function_name=function_name,
old_parameter=old_parameter,
new_parameter=new_parameter,
**message_kwargs,
),
category=DeprecationWarning,
stacklevel=2,
)
Expand Down