human
I wrote the below code

    maxcount = 1000
    suppnmin = 100
    if (fn is None):
        def fun(x):
            return ((x + loc) * self._pmf(x, *args))
    else:
        def fun(x):
            return (fn((x + loc)) * self._pmf(x, *args))
    self._argcheck(*args)
    if (lb is None):
        lb = self.a
    else:
        lb = (lb - loc)
    if (ub is None):
        ub = self.b
    else:
        ub = (ub - loc)
    if conditional:
        invfac = (self.sf(lb, *args) - self.sf((ub + 1), *args))
    else:
        invfac = 1.0
    tot = 0.0
    (low, upp) = (self._ppf(0.001, *args), self._ppf(0.999, *args))
    low = max(min((- suppnmin), low), lb)
    upp = min(max(suppnmin, upp), ub)
    supp = np.arange(low, (upp + 1), self.inc)
    tot = np.sum(fun(supp))
    diff = 1e+100
    pos = (upp + self.inc)
    count = 0
    while ((pos <= ub) and (diff > self.moment_tol) and (count <= maxcount)):
        diff = fun(pos)
        tot += diff
        pos += self.inc
        count += 1
    if (self.a < 0):
        diff = 1e+100
        pos = (low - self.inc)
        while ((pos >= lb) and (diff > self.moment_tol) and (count <= maxcount)):
            diff = fun(pos)
            tot += diff
            pos -= self.inc
            count += 1
    if (count > maxcount):
        print('sum    did    not    converge')
    return (tot / invfac)

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

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