def bind_all(mc, builtin_only=False, stoplist=[],  verbose=False):
    """Recursively apply constant binding to functions in a module or class.

    Use as the last line of the module (after everything is defined, but
    before test code).  In modules that need modifiable globals, set
    builtin_only to True.

    """
    from types import FunctionType, ModuleType

    def _bind_all(mc, builtin_only=False, stoplist=[],  verbose=False):

      if isinstance(mc, (ModuleType, type)):
        for k,v in list(vars(mc).items()):
          if type(v) is FunctionType:
              newv = _make_constants(v, builtin_only, stoplist,  verbose)
              setattr(mc, k, newv)
          elif isinstance(v, type):
              _bind_all(v, builtin_only, stoplist, verbose)

    if isinstance(mc, dict): # allow: bind_all(globals())
      for k,v in list(mc.items()):
        if type(v) is FunctionType:
            newv = _make_constants(v, builtin_only, stoplist,  verbose)
            mc[k] = newv
        elif isinstance(v, type):
            _bind_all(v, builtin_only, stoplist, verbose)
    else:
        _bind_all(v, builtin_only, stoplist, verbose)
Recursively apply constant binding to functions in a module or class.

    Use as the last line of the module (after everything is defined, but
    before test code).  In modules that need modifiable globals, set
    builtin_only to True.

    
recipes/Python/576904_Decorator_BindingConstants_at_compile/recipe-576904.py