Skip to content

Improved self arg deprecations

Compare
Choose a tag to compare
@Borda Borda released this 29 Mar 08:26
· 64 commits to main since this release

Self argument mapping

We also support deprecation and argument mapping for the function itself:

from deprecate import deprecated

@deprecated(
  # define as depreaction some self argument - mapping
  target=True, args_mapping={'coef': 'new_coef'},
  # common version info
  deprecated_in="0.2", remove_in="0.4",
)
def any_pow(base: float, coef: float = 0, new_coef: float = 0) -> float:
    """My function with deprecated argument `coef` mapped to `new_coef`."""
    return base ** new_coef

# call this function will raise deprecation warning:
#   The `any_pow` uses deprecated arguments: `coef` -> `new_coef`.
#   They were deprecated since v0.2 and will be removed in v0.4.
print(any_pow(2, 3))

Eventually, you can set multiple deprecation levels via chaining deprecation arguments as each could be deprecated in another version:

from deprecate import deprecated

@deprecated(
  True, "0.3", "0.6", args_mapping=dict(c1='nc1'),
  template_mgs="Depr: v%(deprecated_in)s rm v%(remove_in)s for args: %(argument_map)s."
)
@deprecated(
  True, "0.4", "0.7", args_mapping=dict(nc1='nc2'),
  template_mgs="Depr: v%(deprecated_in)s rm v%(remove_in)s for args: %(argument_map)s."
)
def any_pow(base, c1: float = 0, nc1: float = 0, nc2: float = 2) -> float:
    return base ** nc2

# call this function will raise deprecation warning:
#   DeprecationWarning('Depr: v0.3 rm v0.6 for args: `c1` -> `nc1`.')
#   DeprecationWarning('Depr: v0.4 rm v0.7 for args: `nc1` -> `nc2`.')
print(any_pow(2, 3))