parameters: (ext_module)
return_statement: return class_decorator
docstring: Decorator to extend an OpView class from an extension module.
  
    Extension modules can expose various entry-points:
      Stand-alone class with the same name as a parent OpView class (i.e.
      "ReturnOp"). A name-based match is attempted first before falling back
      to a below mechanism.
  
      def select_opview_mixin(parent_opview_cls):
        If defined, allows an appropriate mixin class to be selected dynamically
        based on the parent OpView class. Should return NotImplemented if a
        decision is not made.
  
    Args:
      ext_module: A module from which to locate extensions. Can be None if not
        available.
  
    Returns:
      A decorator that takes an OpView subclass and further extends it as
      needed.
docstring_summary: Decorator to extend an OpView class from an extension module.
docstring_tokens: Decorator to extend an OpView class from an extension module .
function: def extend_opview_class(ext_module):
    """Decorator to extend an OpView class from an extension module.
  
    Extension modules can expose various entry-points:
      Stand-alone class with the same name as a parent OpView class (i.e.
      "ReturnOp"). A name-based match is attempted first before falling back
      to a below mechanism.
  
      def select_opview_mixin(parent_opview_cls):
        If defined, allows an appropriate mixin class to be selected dynamically
        based on the parent OpView class. Should return NotImplemented if a
        decision is not made.
  
    Args:
      ext_module: A module from which to locate extensions. Can be None if not
        available.
  
    Returns:
      A decorator that takes an OpView subclass and further extends it as
      needed.
    """
  
    def class_decorator(parent_opview_cls: type):
      if ext_module is None:
        return parent_opview_cls
      mixin_cls = NotImplemented
      # First try to resolve by name.
      try:
        mixin_cls = getattr(ext_module, parent_opview_cls.__name__)
      except AttributeError:
        # Fall back to a select_opview_mixin hook.
        try:
          select_mixin = getattr(ext_module, "select_opview_mixin")
        except AttributeError:
          pass
        else:
          mixin_cls = select_mixin(parent_opview_cls)
  
      if mixin_cls is NotImplemented or mixin_cls is None:
        return parent_opview_cls
  
      # Have a mixin_cls. Create an appropriate subclass.
      try:
  
        class LocalOpView(mixin_cls, parent_opview_cls):
          pass
      except TypeError as e:
        raise TypeError(
            f"Could not mixin {mixin_cls} into {parent_opview_cls}") from e
      LocalOpView.__name__ = parent_opview_cls.__name__
      LocalOpView.__qualname__ = parent_opview_cls.__qualname__
      return LocalOpView
  
    return class_decorator
function_tokens: def extend_opview_class ( ext_module ) : def class_decorator ( parent_opview_cls : type ) : if ext_module is None : return parent_opview_cls mixin_cls = NotImplemented # First try to resolve by name. try : mixin_cls = getattr ( ext_module , parent_opview_cls . __name__ ) except AttributeError : # Fall back to a select_opview_mixin hook. try : select_mixin = getattr ( ext_module , "select_opview_mixin" ) except AttributeError : pass else : mixin_cls = select_mixin ( parent_opview_cls ) if mixin_cls is NotImplemented or mixin_cls is None : return parent_opview_cls # Have a mixin_cls. Create an appropriate subclass. try : class LocalOpView ( mixin_cls , parent_opview_cls ) : pass except TypeError as e : raise TypeError ( f"Could not mixin {mixin_cls} into {parent_opview_cls}" ) from e LocalOpView . __name__ = parent_opview_cls . __name__ LocalOpView . __qualname__ = parent_opview_cls . __qualname__ return LocalOpView return class_decorator