'Transform a Python signature into RST nodes.
Returns (fully qualified name of the thing, classname if any).
If inside a class, the current class name is handled intelligently:
* it is stripped from the displayed name if present
* it is added to the full name (return value) if not present'

def parse_signature(self, sig, signode):

    m = py_sig_re.match(sig)
    if (m is None):
        raise ValueError
    (classname, name, arglist, retann) = m.groups()
    if self.env.currclass:
        add_module = False
        if (classname and classname.startswith(self.env.currclass)):
            fullname = (classname + name)
            classname = classname[len(self.env.currclass):].lstrip('.')
        elif classname:
            fullname = (((self.env.currclass + '.') + classname) + name)
        else:
            fullname = ((self.env.currclass + '.') + name)
    else:
        add_module = True
        fullname = ((classname and (classname + name)) or name)
    prefix = self.get_signature_prefix(sig)
    if prefix:
        signode += addnodes.desc_annotation(prefix, prefix)
    if classname:
        signode += addnodes.desc_addname(classname, classname)
    elif (add_module and self.env.config.add_module_names):
        modname = self.options.get('module', self.env.currmodule)
        if (modname and (modname != 'exceptions')):
            nodetext = (modname + '.')
            signode += addnodes.desc_addname(nodetext, nodetext)
    signode += addnodes.desc_name(name, name)
    if (not arglist):
        if self.needs_arglist():
            signode += addnodes.desc_parameterlist()
        if retann:
            signode += addnodes.desc_returns(retann, retann)
        return (fullname, classname)
    signode += addnodes.desc_parameterlist()
    stack = [signode[(-1)]]
    for token in py_paramlist_re.split(arglist):
        if (token == '['):
            opt = addnodes.desc_optional()
            stack[(-1)] += opt
            stack.append(opt)
        elif (token == ']'):
            try:
                stack.pop()
            except IndexError:
                raise ValueError
        elif ((not token) or (token == ',') or token.isspace()):
            pass
        else:
            token = token.strip()
            stack[(-1)] += addnodes.desc_parameter(token, token)
    if (len(stack) != 1):
        raise ValueError
    if retann:
        signode += addnodes.desc_returns(retann, retann)
    return (fullname, classname)
