class_docstr: Metaclass for `Module`.
class_docstr_tok: ["Metaclass","for","`","Module","`","."]
code: def __new__(  # pylint: disable=bad-classmethod-argument
      mcs: type[type[T]],
      name: str,
      bases: tuple[type[Any], ...],
      clsdict: dict[str, Any],
  ) -> type[T]:
      method_names = []
      cls_fut = Future()
  
      for key, value in clsdict.items():
          if key == "module_name":
              # Don't patch `module_name` in case the user implemented it as a
              # computed property.
              continue
  
          elif key.startswith("__") and key != "__call__":
              # Don't patch methods like `__getattr__` or `__del__`.
              continue
  
          elif isinstance(value, property):
              # TODO(tomhennigan) Preserve the type of property subclasses.
              p = value
              clsdict[key] = property(
                  p.fget
                  if not p.fget
                  else wrap_method(key, p.fget, cls_fut.result),
                  p.fset
                  if not p.fset
                  else wrap_method(key, p.fset, cls_fut.result),
                  p.fdel
                  if not p.fdel
                  else wrap_method(key, p.fdel, cls_fut.result),
                  doc=value.__doc__,
              )
  
          elif inspect.isfunction(value):
              # We defer patching methods until after the type is created such that we
              # can trigger the descriptor binding them to the class.
              method_names.append(key)
  
      # Without this any classes with @abc.abstract* elements in their dict fail
      # isinstance checks.
      # TODO(b/177339347): Remove this workaround once the underlying bug in
      #                    `_ProtocolMeta.__instancecheck__` has been fixed.
      clsdict.setdefault("_is_protocol", False)
  
      clsdict.setdefault(
          "__repr__", lambda module: module._auto_repr
      )  # pylint: disable=protected-access
  
      cls = super().__new__(mcs, name, bases, clsdict)
  
      # Provides access to the class object to method interceptors.
      cls_fut.set_result(cls)
  
      for method_name in method_names:
          # Note: the code below is subtle, we need to ensure that we're wrapping
          # the method bound to the class. In some cases (e.g. `wrapt`) this is
          # important since the method can trigger different behavior when it is
          # bound (e.g. in wrapt `FunctionWrapper.__get__(None, cls)` produces a
          # `BoundFunctionWrapper` which in turn populates the `instance` argument
          # to decorator functions using args[0]).
          # Equivalent to: `cls.__dict__[method_name].__get__(None, cls)`
          method = getattr(cls, method_name)
          method = wrap_method(method_name, method, cls_fut.result)
          setattr(cls, method_name, method)
  
      return cls
  
imports: from collections.abc import Mapping
  import contextlib
  import functools
  import inspect
  import re
  from typing import Any, Callable, ContextManager, NamedTuple, Optional, Protocol, TypeVar
  from haiku._src import base
  from haiku._src import config
  from haiku._src import data_structures
  from haiku._src import utils
  import jax
  import jax.numpy
label_desc: Use image node_id 1 for calling the ModuleMetaclass obj's underlying member method code with example usage: obj.__new__(mcs, name, bases, clsdict) and returns: cls