code: def _create_qfunc_internal_wrapper(
      fn, tape_transform, transform_args, transform_kwargs
  ):  # pragma: no cover
      """Convenience function to create the internal wrapper function
      generated by the qfunc_transform decorator"""
      if isinstance(fn, qml.Device):
          new_dev = deepcopy(fn)
  
          @new_dev.custom_expand
          def new_expand_fn(
              self, tape, *args, **kwargs
          ):  # pylint: disable=unused-variable
              tape = tape_transform(
                  tape, *transform_args, **transform_kwargs
              )
              return self.default_expand_fn(tape, *args, **kwargs)
  
          return new_dev
  
      if isinstance(fn, qml.tape.QuantumScript):
          return tape_transform(fn, *transform_args, **transform_kwargs)
  
      if not callable(fn):
          raise ValueError(
              f"The qfunc to transform, {fn}, does not appear "
              "to be a valid Python function or callable."
          )
      if isinstance(fn, qml.QNode):
          raise ValueError(
              "QNodes cannot be declared as qfunc transforms."
          )
  
      @functools.wraps(fn)
      def internal_wrapper(*args, **kwargs):
          tape = make_qscript(fn)(*args, **kwargs)
          tape = tape_transform(
              tape, *transform_args, **transform_kwargs
          )
  
          num_measurements = len(tape.measurements)
          if num_measurements == 0:
              return None
          return (
              tape.measurements[0]
              if num_measurements == 1
              else tape.measurements
          )
  
      return internal_wrapper
  
file_path: pennylane/pennylane/transforms/qfunc_transforms.py
imports: from copy import deepcopy
  import functools
  import inspect
  import os
  import warnings
  import pennylane
  from pennylane.tape import make_qscript
label_desc: Use image node_id 2 for calling a global function with example usage: _create_qfunc_internal_wrapper(fn, tape_transform, transform_args, transform_kwargs) and returns: internal_wrapper, new_dev, tape_transform, unknown, self, None