human
I wrote the below code

    if (fn is None):
        def fun(x, *args):
            return ((loc + (x * scale)) * self._pdf(x, *args))
    else:
        def fun(x, *args):
            return (fn((loc + (x * scale))) * self._pdf(x, *args))
    if (lb is None):
        try:
            lb = self.ppf(1e-09, *args)
        except ValueError:
            lb = self.a
    else:
        lb = max(self.a, ((lb - loc) / (1.0 * scale)))
    if (ub is None):
        try:
            ub = self.ppf((1 - 1e-09), *args)
        except ValueError:
            ub = self.b
    else:
        ub = min(self.b, ((ub - loc) / (1.0 * scale)))
    if conditional:
        invfac = (self._sf(lb, *args) - self._sf(ub, *args))
    else:
        invfac = 1.0
    return (integrate.quad(fun, lb, ub, args=args, limit=500)[0] / invfac)

What's a good function header?
assistant
#Here's a good function header.

def expect_v2(self, fn=None, args=(), loc=0, scale=1, lb=None, ub=None, conditional=False):