# Buggy code
def make_xref(self, rolename, domain, target, innernode=nodes.emphasis, contnode=None):
    result = super(PyXrefMixin, self).make_xref(
        rolename, domain, target, innernode, contnode
    )
    result["refspecific"] = True
    if target.startswith("."):
        result["reftarget"] = target[1:]
        result[0][0] = nodes.Text(target[1:])
    if target.startswith("~"):
        result["reftarget"] = target[1:]
        title = target.split(".")[-1]
        result[0][0] = nodes.Text(title)
    return result


# Traceback (TypeError)
# Sphinx version: 1.3
# Python version: 2.7.9 (CPython)
# Docutils version: 0.12 release
# Jinja2 version: 2.7.3
# Last messages:
#   reading sources... [ 19%] library/cg/index
#   reading sources... [ 20%] library/cg/kdtree
#   reading sources... [ 20%] library/cg/locators
#   reading sources... [ 21%] library/cg/rtree
#   reading sources... [ 22%] library/cg/shapes
#   reading sources... [ 23%] library/cg/sphere
#   reading sources... [ 24%] library/cg/standalone
#   reading sources... [ 25%] library/contrib/index
#   reading sources... [ 25%] library/core/FileIO
#   reading sources... [ 26%] library/core/IOHandlers/arcgis_dbf
# Loaded extensions:
#   sphinx.ext.graphviz (1.3) from /home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/ext/graphviz.pyc
#   sphinx.ext.autodoc (1.3) from /home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/ext/autodoc.pyc
#   sphinx.ext.intersphinx (1.3) from /home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/ext/intersphinx.pyc
#   sphinx.ext.doctest (1.3) from /home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/ext/doctest.pyc
#   alabaster (0.7.2) from /home/jlaura/anaconda/lib/python2.7/site-packages/alabaster/__init__.pyc
#   sphinx.ext.viewcode (1.3) from /home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/ext/viewcode.pyc
#   sphinx.ext.pngmath (1.3) from /home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/ext/pngmath.pyc
#   sphinx.ext.napoleon (1.3) from /home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/ext/napoleon/__init__.pyc
Traceback (most recent call last):
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/cmdline.py", line 245, in main
    app.build(opts.force_all, filenames)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/application.py", line 264, in build
    self.builder.build_update()
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 240, in build_update
    'out of date' % len(to_build))
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/builders/__init__.py", line 254, in build
    self.doctreedir, self.app))
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/environment.py", line 617, in update
    self._read_serial(docnames, app)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/environment.py", line 637, in _read_serial
    self.read_doc(docname, app)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/environment.py", line 790, in read_doc
    pub.publish()
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/core.py", line 217, in publish
    self.settings)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/environment.py", line 125, in read
    self.parse()
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/readers/__init__.py", line 78, in parse
    self.parser.parse(self.input, document)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/__init__.py", line 172, in parse
    self.statemachine.run(inputlines, document, inliner=self.inliner)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 170, in run
    input_source=document['source'])
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2726, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 327, in section
    self.new_subsection(title, lineno, messages)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 395, in new_subsection
    node=section_node, match_titles=True)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 282, in nested_parse
    node=node, match_titles=match_titles)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2301, in explicit_markup
    self.explicit_list(blank_finish)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2331, in explicit_list
    match_titles=self.state_machine.match_titles)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 319, in nested_list_parse
    node=node, match_titles=match_titles)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2604, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2311, in explicit_construct
    return method(self, expmatch)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2054, in directive
    directive_class, match, type_name, option_presets)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2103, in run_directive
    result = directive_instance.run()
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 1488, in run
    nested_parse_with_titles(self.state, self.result, node)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/util/nodes.py", line 165, in nested_parse_with_titles
    return state.nested_parse(content, 0, node, match_titles=1)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 282, in nested_parse
    node=node, match_titles=match_titles)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2301, in explicit_markup
    self.explicit_list(blank_finish)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2331, in explicit_list
    match_titles=self.state_machine.match_titles)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 319, in nested_list_parse
    node=node, match_titles=match_titles)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2604, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2311, in explicit_construct
    return method(self, expmatch)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2054, in directive
    directive_class, match, type_name, option_presets)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2103, in run_directive
    result = directive_instance.run()
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/domains/__init__.py", line 197, in run
    return BaseDirective.run(self)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/directives/__init__.py", line 156, in run
    self.state.nested_parse(self.content, self.content_offset, contentnode)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 282, in nested_parse
    node=node, match_titles=match_titles)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2301, in explicit_markup
    self.explicit_list(blank_finish)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2331, in explicit_list
    match_titles=self.state_machine.match_titles)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 319, in nested_list_parse
    node=node, match_titles=match_titles)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 239, in run
    context, state, transitions)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/statemachine.py", line 460, in check_line
    return method(match, context, next_state)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2604, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2311, in explicit_construct
    return method(self, expmatch)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2054, in directive
    directive_class, match, type_name, option_presets)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/docutils/parsers/rst/states.py", line 2103, in run_directive
    result = directive_instance.run()
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/domains/__init__.py", line 197, in run
    return BaseDirective.run(self)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/directives/__init__.py", line 157, in run
    DocFieldTransformer(self).transform_all(contentnode)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/util/docfields.py", line 210, in transform_all
    self.transform(child)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/util/docfields.py", line 302, in transform
    content)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/util/docfields.py", line 177, in make_field
    bodynode += nodes.list_item('', handle_item(fieldarg, content))
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/util/docfields.py", line 153, in handle_item
    addnodes.literal_strong)
  File "/home/jlaura/anaconda/lib/python2.7/site-packages/sphinx/domains/python.py", line 95, in make_xref
    result[0][0] = nodes.Text(target[1:])
TypeError: 'Text' object does not support item assignment


# Fixed code
def make_xref(self, rolename, domain, target, innernode=nodes.emphasis, contnode=None):
    result = super(PyXrefMixin, self).make_xref(
        rolename, domain, target, innernode, contnode
    )
    result["refspecific"] = True
    if target.startswith((".", "~")):
        prefix, result["reftarget"] = target[0], target[1:]
        if prefix == ".":
            text = target[1:]
        elif prefix == "~":
            text = target.split(".")[-1]
        for node in result.traverse(nodes.Text):
            node.parent[node.parent.index(node)] = nodes.Text(text)
            break
    return result