code: def make_weighted_distribution(dist: pm.Distribution):
      wlogp = make_weighted_logp(dist)
      dist_args = get_dist_args(dist)
  
      try:
          dname = dist.rv_op._print_name[0]
      except:
          dname = "Dist"
  
      cdist = create_cdist(dist)
      class_name = f"Weighted{dname}"
  
      class WeightedDistribution:
          # We pass 'logp' to get the weighted logp, and we pass 'dist' to make sure
          # the random draws are generated using the correct parameter values.
          # Distribution.dist is the method that handles the parameters and with this approach
          # we are sure that we use it.
          def __new__(cls, name, weights, **kwargs):
              # Get parameter values in the order required by the distribution as they are passed
              # by position to `pm.CustomDist`
              dist_params = [
                  kwargs.pop(arg) for arg in dist_args if arg in kwargs
              ]
              return pm.CustomDist(
                  name,
                  *dist_params,
                  logp=partial(wlogp, weights=weights),
                  dist=cdist,
                  class_name=class_name,
                  **kwargs,
              )
  
          @classmethod
          def dist(cls, **kwargs):
              dist_params = [
                  kwargs.pop(arg) for arg in dist_args if arg in kwargs
              ]
              weights = (
                  1
                  if "weights" not in kwargs
                  else kwargs.pop("weights")
              )
              return pm.CustomDist.dist(
                  *dist_params,
                  logp=partial(wlogp, weights=weights),
                  dist=cdist,
                  class_name=class_name,
                  **kwargs,
              )
  
      return WeightedDistribution
  
file_path: bambi/bambi/backend/utils.py
imports: import inspect
  from functools import partial
  import pytensor.tensor
  import pymc
label_desc: Use image node_id 12 for calling a global function with example usage: make_weighted_distribution(dist) and returns: WeightedDistribution, pm, pm