torchx.deprecations¶
Platform-agnostic deprecation utilities for TorchX.
Provides deprecated_module() for warning about moved import
paths and deprecated() for marking functions/classes as deprecated.
Both emit UserWarning (not DeprecationWarning) so that
warnings are always visible to end users — DeprecationWarning is
silenced by default outside __main__.
For Meta-internal use (fbsource-specific path resolution and sed commands),
see torchx.fb.deprecations which layers on top of this module.
- torchx.deprecations.deprecated_module(old_import: str, new_import: str, *, stacklevel: int = 3) None[source]¶
Emit a
UserWarningfor a moved module import.Call this from backwards-compatibility stub modules so users see a warning on first import:
# torchx/old/path.py (BC stub) from torchx.deprecations import deprecated_module deprecated_module( old_import="torchx.old.path", new_import="torchx.new.path", ) from torchx.new.path import * # noqa: F401,F403
- Parameters:
old_import – The deprecated import path.
new_import – The replacement import path.
stacklevel – Stack level for the warning. Default
3works when called from module-level code in a stub (caller -> stub -> this function ->warnings.warn).
- torchx.deprecations.deprecated(*, replacement: str | None = None) Callable[[_F], _F][source]¶
Mark a function or class as deprecated.
from torchx.deprecations import deprecated @deprecated(replacement="new_func") def old_func(): ...
- Parameters:
replacement – Name or import path of the replacement, if any.
- Returns:
A decorator that wraps the target to emit
UserWarningon each call.