code: def evaluate_object(obj, cls=None, cache=False, **kwargs):
          
          old_obj = obj
          if isinstance(obj, Element):
              if cache:
                  obj = obj.evaluate_cached(**kwargs)
              else:
                  obj = obj.evaluate(cache=cache, **kwargs)
  
          if cls is not None and type(obj) != cls:
              obj = cls(obj)
  
          for attr in ('string', 'location', 'tokens'):
              if hasattr(old_obj, attr):
                  setattr(obj, attr, getattr(old_obj, attr))
  
          return obj
docs: Evaluates elements, and coerces objects to a class if needed