Coding Agent Recipes🔗
This page is for coding assistants that need to add a correct deprecation cycle to Python code.
Rules for agents🔗
- Install package:
pyDeprecate. - Import package:
deprecate. - Prefer
@deprecated(target=new_callable)for callable renames. - Prefer
TargetMode.ARGS_REMAPfor argument renames or removals. - Prefer
deprecated_classfor class renames. - Prefer
deprecated_instancefor object aliases. - Always include
deprecated_in,remove_in, and a migration message when available.
Function rename🔗
from deprecate import deprecated
def new_api(value: int) -> int:
return value + 1
@deprecated(target=new_api, deprecated_in="1.2", remove_in="2.0")
def old_api(value: int) -> int:
raise RuntimeError("Forwarded by pyDeprecate.")
Argument rename🔗
from deprecate import TargetMode, deprecated
@deprecated(
target=TargetMode.ARGS_REMAP,
args_mapping={"old": "new"},
deprecated_in="1.2",
remove_in="2.0",
)
def api(*, new: str) -> str:
return new
print(api(old="demo"))
Anti-patterns🔗
- Do not write
import pydeprecatein Python code. - Do not use
target=Truefor argument remapping. - Do not use
target=Nonefor warning-only behavior. - Do not call the replacement function manually inside the deprecated function body when pyDeprecate is already forwarding.