core.ops._compat#

Deprecated import-path forwarding for modules that moved into megatron.core.ops.

A forwarder module is two lines::

from megatron.core.ops._compat import deprecated_module
__getattr__, __dir__ = deprecated_module(__name__, "megatron.core.ops.ssm.mamba2.mixer")

It resolves every attribute lazily through PEP 562 module __getattr__, so importing the old path does not import the new module (or its optional kernel dependencies) until a name is actually used. from old import *, private names, and pickles that recorded the old __module__ all keep working, and every object is the canonical one – no copies.

Writes go the same way as reads. Assigning or deleting a name on a forwarder – including mock.patch and monkeypatch.setattr on the old path – changes the module the name is read from, so a patch through the old path still reaches the code that uses it.

The forwarder emits a DeprecationWarning once per process at import. It never adds an import hook or alias registry; it is a plain module that can be deleted on the removal date.

Module Contents#

Classes#

_ForwarderModule

Module type of a forwarder: names it does not hold itself are written where they are read.

Functions#

deprecated_module

Return (__getattr__, __dir__) for a forwarder at old_name.

Data#

API#

core.ops._compat.REMOVAL_VERSION#

‘0.22’

core.ops._compat._OWNER#

‘forwarder_owner’

core.ops._compat._ORIGINALS#

‘forwarder_originals’

core.ops._compat._MISSING#

‘object(…)’

class core.ops._compat._ForwarderModule#

Bases: types.ModuleType

Module type of a forwarder: names it does not hold itself are written where they are read.

Without this, setattr on a forwarder would only shadow the name in the forwarder, and a patch applied through the old path would silently leave the implementation untouched.

A written name also stays in the forwarder’s own namespace until the write ends, as on any patched module, because patch tools choose how to undo from the target’s __dict__: mock.patch and pytest 9.2+ monkeypatch restore a name the target held by assigning the value they saved, so nested patches unwind by assignment, and remove a name it did not hold by deleting it. Deleting the name, or assigning the original back as monkeypatch does before pytest 9.2, ends the write and restores what the implementation held before it. A first write starts one even when it assigns the value the name already has, so the deletion that undoes it has a write to end. Reads of a written name still come from the implementation.

__getattribute__(name: str) → object#
__setattr__(name: str, value: object) → None#
__delattr__(name: str) → None#
core.ops._compat.deprecated_module(
old_name: str,
*targets: str,
exports: Mapping[str, str] | None = None,
removal_version: str = REMOVAL_VERSION,
) → tuple[Callable[[str], object], Callable[[], list[str]]]#

Return (__getattr__, __dir__) for a forwarder at old_name.

targets are tried in order, so a module that was split during the move can list each new home. The first target is the documented replacement in the warning.

exports maps the names a historical package re-exported to the modules that define them. Those names resolve there and form the forwarder’s __all__, so the canonical package does not have to keep re-exporting them.