"""
python patches for NPU adaptation.
Provides NPU-compatible replacements for python operators including:
- CollectionsCompat
"""
from mx_driving.patcher.patch import (
LegacyPatch,
Patch,
)
class CollectionsCompat(Patch):
"""Iterable patch for collections."""
name = "Iterable"
legacy_name = "Iterable"
target_module = "python"
apply_before_collect = True
@staticmethod
def _patch_deprecated_aliases(collections, _options):
changed = False
if not hasattr(collections, "Iterable"):
collections.Iterable = collections.abc.Iterable
changed = True
if not changed:
raise AttributeError(
"deprecated aliases already exist in this python runtime; CollectionsCompat is not needed"
)
@classmethod
def patches(cls, options=None):
return [
LegacyPatch(cls._patch_deprecated_aliases, target_module="collections", options=options),
]