'Return a hit for a getattr on the given element.
Returns <hit> or raises CodeIntelError if cannot resolve.'

def _hit_from_getattr(self, token, elem, scoperef):

    if (elem.tag == 'variable'):
        elem_is_var_on_entry = True
        (elem, scoperef) = self._hit_from_variable_type_inference(elem, scoperef)
    else:
        elem_is_var_on_entry = False
    assert (elem.tag == 'scope')
    ilk = elem.get('ilk')
    if (ilk == 'class'):
        attr = elem.names.get(token)
        if (attr is not None):
            return (attr, (scoperef[0], (scoperef[1] + [token])))
        if elem_is_var_on_entry:
            for (base_mod, base_pkg) in self._inherited_mods_and_pkgs_from_pkg(elem):
                attr = base_pkg.names.get(token)
                if (attr is not None):
                    return (attr, (base_mod, [base_pkg.get('name')]))
    elif (ilk == 'blob'):
        raise CodeIntelError(("didn't    expect    a    getattr    on    a    Perl    module:    %r    on    %r" % (token, elem)))
    elif (ilk == 'function'):
        raise CodeIntelError(('cannot    get    attributes    of    a    function:    %r    on    %r' % (token, elem)))
    else:
        raise NotImplementedError(('unexpected    scope    ilk:    %r' % ilk))
    raise CodeIntelError(("could    not    resolve    '%s'    attr    on    %s" % (token, elem)))
