parameters: (clz, globals=None)
docstring: Looks for all attributes in clz, if anyone is a CachedProperty instance,
      which is a sential wrapper for methods, then create a cached attribute using
      dataclass language, set them as pytree_node=False so they are untracked.
docstring_summary: Looks for all attributes in clz, if anyone is a CachedProperty instance,
      which is a sential wrapper for methods, then create a cached attribute using
      dataclass language, set them as pytree_node=False so they are untracked.
docstring_tokens: Looks for all attributes in clz if anyone is a CachedProperty instance which is a sential wrapper for methods then create a cached attribute using dataclass language set them as pytree_node = False so they are untracked .
function: def process_cached_properties(clz, globals=None):
      """Looks for all attributes in clz, if anyone is a CachedProperty instance,
      which is a sential wrapper for methods, then create a cached attribute using
      dataclass language, set them as pytree_node=False so they are untracked.
      """
  
      if globals is None:
          globals = {}
  
      cached_props = {}
      self_name = "self"
  
      for name, field_info in clz.__dict__.items():
          if isinstance(field_info, CachedProperty):
              cached_props[name] = field_info
  
      # Convert a property to something like this
      # @cached_property
      # def myproperty(self) -> T
      #   return val
      #
      # becomes
      #
      # __myproperty_cache : T = UNINITIALIZED
      # @property
      # def myproperty(self) -> T
      #    if self.__myproperty_cache is Uninitialized:
      #        setattr(self, '__myproperty_cache', self.__myproperty())
      #    return self.__myproperty_cache
  
      # create the compute method
      for name, cp in cached_props.items():
          _set_new_attribute(clz, _compute_cache_name(name), cp.method)
  
      # Create the actual property accessor method
      for name, cp in cached_props.items():
          cache_name = _cache_name(name)
          compute_name = _compute_cache_name(name)
  
          # create accessor method
          body_lines = [
              f"if {self_name}.{cache_name} is Uninitialized:",
              f"\tBUILTINS.object.__setattr__({self_name},{cache_name!r},self.{compute_name}())",
              "",
              f"return {self_name}.{cache_name}",
          ]
  
          fun = _create_fn(
              name,
              [self_name],
              body_lines,
              return_type=cp.type,
              globals=globals,
              doc=cp.doc,
          )
          prop_fun = property(fun)
          setattr(clz, name, prop_fun)
  
      # merge caches among levels:
      for b in clz.__mro__[1:]:
          # Only process classes that have been processed by our
          # decorator.  That is, they have a _FIELDS attribute.
          for (name, cp) in getattr(b, _CACHES, {}).items():
              if name not in cached_props:
                  cached_props[name] = cp
  
      # Create the cache member
      for name, cp in cached_props.items():
          cache_name = _cache_name(name)
  
          # Create the dataclass attribute
          _cache = field(
              pytree_node=cp.pytree_node,
              serialize=False,
              cache=True,
              default=Uninitialized,
              repr=False,
              hash=False,
              init=True,
              compare=False,
          )
          _set_new_attribute(clz, cache_name, _cache)
          _set_annotation(clz, cache_name, cp.type)
  
      # create precompute method
      _precompute_body_method = []
      for name in cached_props.keys():
          _precompute_body_method.append(f"{self_name}.{name}")
  
      # Create the precompute method
      if len(_precompute_body_method) == 0:
          _precompute_body_method.append("pass")
  
      fun = _create_fn(
          PRECOMPUTE_CACHED_PROPERTY_NAME,
          [self_name],
          _precompute_body_method,
          globals=globals,
          doc="Precompute the value of all cached properties",
      )
      setattr(clz, PRECOMPUTE_CACHED_PROPERTY_NAME, fun)
  
      setattr(clz, _CACHES, cached_props)
function_tokens: def process_cached_properties ( clz , globals = None ) : if globals is None : globals = { } cached_props = { } self_name = "self" for name , field_info in clz . __dict__ . items ( ) : if isinstance ( field_info , CachedProperty ) : cached_props [ name ] = field_info # Convert a property to something like this # @cached_property # def myproperty(self) -> T #   return val # # becomes # # __myproperty_cache : T = UNINITIALIZED # @property # def myproperty(self) -> T #    if self.__myproperty_cache is Uninitialized: #        setattr(self, '__myproperty_cache', self.__myproperty()) #    return self.__myproperty_cache # create the compute method for name , cp in cached_props . items ( ) : _set_new_attribute ( clz , _compute_cache_name ( name ) , cp . method ) # Create the actual property accessor method for name , cp in cached_props . items ( ) : cache_name = _cache_name ( name ) compute_name = _compute_cache_name ( name ) # create accessor method body_lines = [ f"if {self_name}.{cache_name} is Uninitialized:" , f"\tBUILTINS.object.__setattr__({self_name},{cache_name!r},self.{compute_name}())" , "" , f"return {self_name}.{cache_name}" , ] fun = _create_fn ( name , [ self_name ] , body_lines , return_type = cp . type , globals = globals , doc = cp . doc , ) prop_fun = property ( fun ) setattr ( clz , name , prop_fun ) # merge caches among levels: for b in clz . __mro__ [ 1 : ] : # Only process classes that have been processed by our # decorator.  That is, they have a _FIELDS attribute. for ( name , cp ) in getattr ( b , _CACHES , { } ) . items ( ) : if name not in cached_props : cached_props [ name ] = cp # Create the cache member for name , cp in cached_props . items ( ) : cache_name = _cache_name ( name ) # Create the dataclass attribute _cache = field ( pytree_node = cp . pytree_node , serialize = False , cache = True , default = Uninitialized , repr = False , hash = False , init = True , compare = False , ) _set_new_attribute ( clz , cache_name , _cache ) _set_annotation ( clz , cache_name , cp . type ) # create precompute method _precompute_body_method = [ ] for name in cached_props . keys ( ) : _precompute_body_method . append ( f"{self_name}.{name}" ) # Create the precompute method if len ( _precompute_body_method ) == 0 : _precompute_body_method . append ( "pass" ) fun = _create_fn ( PRECOMPUTE_CACHED_PROPERTY_NAME , [ self_name ] , _precompute_body_method , globals = globals , doc = "Precompute the value of all cached properties" , ) setattr ( clz , PRECOMPUTE_CACHED_PROPERTY_NAME , fun ) setattr ( clz , _CACHES , cached_props )