Skip to content

Commit

Permalink
update names
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis-Dupont committed Aug 30, 2023
1 parent 4bc4303 commit 65fc918
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
20 changes: 10 additions & 10 deletions src/super_gradients/common/deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
from pkg_resources import parse_version


def deprecated(deprecated_in_v: str, remove_in_v: str, target: Optional[callable] = None, reason: str = ""):
def deprecated(deprecated_since: str, removed_from: str, target: Optional[callable] = None, reason: str = ""):
"""
Decorator to mark a callable as deprecated. Works on functions and classes.
It provides a clear and actionable warning message informing
the user about the version in which the function was deprecated, the version in which it will be removed,
and guidance on how to replace it.
:param deprecated_in_v: Version number when the function was deprecated.
:param remove_in_v: Version number when the function will be removed.
:param target: (Optional) The new function that should be used as a replacement. If provided, it will guide the user to the updated function.
:param reason: (Optional) Additional information or reason for the deprecation.
:param deprecated_since: Version number when the function was deprecated.
:param removed_from: Version number when the function will be removed.
:param target: (Optional) The new function that should be used as a replacement. If provided, it will guide the user to the updated function.
:param reason: (Optional) Additional information or reason for the deprecation.
Example usage:
If a direct replacement function exists:
>> from new.module.path import new_get_local_rank
>> @deprecated(deprecated_in_v='3.2.0', remove_in_v='4.0.0', target=new_get_local_rank, reason="Replaced for optimization")
>> @deprecated(deprecated_since='3.2.0', removed_from='4.0.0', target=new_get_local_rank, reason="Replaced for optimization")
>> def get_local_rank():
>> return new_get_local_rank()
If there's no direct replacement:
>> @deprecated(deprecated_in_v='3.2.0', remove_in_v='4.0.0', reason="Function is no longer needed due to XYZ reason")
>> @deprecated(deprecated_since='3.2.0', removed_from='4.0.0', reason="Function is no longer needed due to XYZ reason")
>> def some_old_function():
>> # ... function logic ...
Expand All @@ -45,11 +45,11 @@ def wrapper(*args, **kwargs):
if not wrapper._warned:
import super_gradients

is_still_supported = parse_version(super_gradients.__version__) < parse_version(remove_in_v)
is_still_supported = parse_version(super_gradients.__version__) < parse_version(removed_from)
status_msg = "is deprecated" if is_still_supported else "was deprecated and has been removed"
message = (
f"Callable `{old_func.__module__}.{old_func.__name__}` {status_msg} since version `{deprecated_in_v}` "
f"and will be removed in version `{remove_in_v}`.\n"
f"Callable `{old_func.__module__}.{old_func.__name__}` {status_msg} since version `{deprecated_since}` "
f"and will be removed in version `{removed_from}`.\n"
)
if reason:
message += f"Reason: {reason}.\n"
Expand Down
8 changes: 4 additions & 4 deletions src/super_gradients/training/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
from super_gradients.training.utils import make_divisible as _make_divisible_current_version, HpmStruct as CurrVersionHpmStruct


@deprecated(deprecated_in_v="3.1.0", remove_in_v="3.4.0", target=_make_divisible_current_version)
@deprecated(deprecated_since="3.1.0", removed_from="3.4.0", target=_make_divisible_current_version)
def make_divisible(x: int, divisor: int, ceil: bool = True) -> int:
"""
Returns x evenly divisible by divisor.
Expand All @@ -144,17 +144,17 @@ def make_divisible(x: int, divisor: int, ceil: bool = True) -> int:
return _make_divisible_current_version(x=x, divisor=divisor, ceil=ceil)


@deprecated(deprecated_in_v="3.1.0", remove_in_v="3.4.0", target=BasicResNetBlock, reason="This block was renamed to BasicResNetBlock for better clarity.")
@deprecated(deprecated_since="3.1.0", removed_from="3.4.0", target=BasicResNetBlock, reason="This block was renamed to BasicResNetBlock for better clarity.")
class BasicBlock(BasicResNetBlock):
...


@deprecated(deprecated_in_v="3.1.0", remove_in_v="3.4.0", target=NewBottleneck, reason="This block was renamed to BasicResNetBlock for better clarity.")
@deprecated(deprecated_since="3.1.0", removed_from="3.4.0", target=NewBottleneck, reason="This block was renamed to BasicResNetBlock for better clarity.")
class Bottleneck(NewBottleneck):
...


@deprecated(deprecated_in_v="3.1.0", remove_in_v="3.4.0", target=CurrVersionHpmStruct)
@deprecated(deprecated_since="3.1.0", removed_from="3.4.0", target=CurrVersionHpmStruct)
class HpmStruct(CurrVersionHpmStruct):
...

Expand Down
10 changes: 5 additions & 5 deletions tests/unit_tests/test_deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def setUp(self):
def new_func():
return self.new_function_message

@deprecated(deprecated_in_v="3.2.0", remove_in_v="10.0.0", target=new_func, reason="Replaced for optimization")
@deprecated(deprecated_since="3.2.0", removed_from="10.0.0", target=new_func, reason="Replaced for optimization")
def fully_configured_deprecated_func():
return new_func()

@deprecated(deprecated_in_v="3.2.0", remove_in_v="10.0.0")
@deprecated(deprecated_since="3.2.0", removed_from="10.0.0")
def basic_deprecated_func():
return new_func()

Expand All @@ -29,7 +29,7 @@ class NewClass:
def __init__(self):
pass

@deprecated(deprecated_in_v="3.2.0", remove_in_v="10.0.0", target=NewClass, reason="Replaced for optimization")
@deprecated(deprecated_since="3.2.0", removed_from="10.0.0", target=NewClass, reason="Replaced for optimization")
class DeprecatedClass:
def __init__(self):
pass
Expand Down Expand Up @@ -111,7 +111,7 @@ def test_raise_error_when_library_version_equals_removal_version(self):
with patch("super_gradients.__version__", "10.1.0"): # Mocking the version to be equal to removal version
with self.assertRaises(ImportError):

@deprecated(deprecated_in_v="3.2.0", remove_in_v="10.1.0", target=self.new_func)
@deprecated(deprecated_since="3.2.0", removed_from="10.1.0", target=self.new_func)
def deprecated_func_version_equal():
return

Expand All @@ -121,7 +121,7 @@ def test_no_error_when_library_version_below_removal_version(self):
"""Ensure that no error is raised when the library's version is below the function's removal version."""
with patch("super_gradients.__version__", "10.1.0"): # Mocking the version to be below removal version

@deprecated(deprecated_in_v="3.2.0", remove_in_v="10.2.0", target=self.new_func)
@deprecated(deprecated_since="3.2.0", removed_from="10.2.0", target=self.new_func)
def deprecated_func_version_below():
return

Expand Down

0 comments on commit 65fc918

Please sign in to comment.