Does Param have a concept of unions of types?

Say I’m trying to write a param.ParameterizedFunction subclass that wraps a function f:

def f(x: str | int): ...

Does param have a way to represent the x parameter that captures that x may either be a str or an int? I know if the annotation were str | None that I could use the allow_None option, but for the general case of any union I’m not sure what to use.

yes. Here is an example:

p = param.ClassSelector(class_=(int, float, dict, types.FunctionType, np.ndarray),
                                     default=15, doc="my param")

You can then use isinstance to recover the proper type:

      # ✅ Scalar (int, float, str)
      if isinstance(p, (int, float, str)):
          return p

      # ✅ Numpy array: use correct index
      if isinstance(p, np.ndarray):
           ....

Oh thanks!

Is there also a way to specify one or more parameter subclasses?

Do you mean a union of Parameters? If so that doesn’t exist in Param yet.

Yeah that was what I was thinking. Good to know!