# Buggy code
def wire_names(self, with_initial_state=False):
    """Returns a list of names for each wire.

    Args:
        with_initial_state (bool): Optional (Default: False). If true, adds
            the initial value to the name.

    Returns:
        List: The list of wire names.
    """
    if with_initial_state:
        initial_qubit_value = "|0>"
        initial_clbit_value = "0 "
    else:
        initial_qubit_value = ""
        initial_clbit_value = ""

    qubit_labels = []
    if self.layout is None:
        for bit in self.qregs:
            label = "{name}_{index}: " + initial_qubit_value
            qubit_labels.append(
                label.format(name=bit.register.name, index=bit.index, physical="")
            )
    else:
        for bit in self.qregs:
            label = "{name}_{index} -> {physical} " + initial_qubit_value
            qubit_labels.append(
                label.format(
                    name=self.layout[bit.index].register.name,
                    index=self.layout[bit.index].index,
                    physical=bit.index,
                )
            )
    clbit_labels = []
    previous_creg = None
    for bit in self.cregs:
        if self.cregbundle:
            if previous_creg == bit.register:
                continue
            previous_creg = bit.register
            label = "{name}: {initial_value}{size}/"
            clbit_labels.append(
                label.format(
                    name=bit.register.name,
                    initial_value=initial_clbit_value,
                    size=bit.register.size,
                )
            )
        else:
            label = "{name}_{index}: " + initial_clbit_value
            clbit_labels.append(label.format(name=bit.register.name, index=bit.index))
    return qubit_labels + clbit_labels


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
700                 type_pprinters=self.type_printers,
701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
703             printer.flush()
704             return stream.getvalue()

~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
392                         if cls is not object \
393                                 and callable(cls.__dict__.get('__repr__')):
--> 394                             return _repr_pprint(obj, self, cycle)
395
396             return _default_pprint(obj, self, cycle)

~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
698     """A pprint that just redirects to the normal repr function."""
699     # Find newlines and replace them with p.break_()
--> 700     output = repr(obj)
701     lines = output.splitlines()
702     with p.group():

~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/qiskit/visualization/text.py in __repr__(self)
546
547     def __repr__(self):
--> 548         return self.single_string()
549
550     def single_string(self):

~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/qiskit/visualization/text.py in single_string(self)
554             str: The lines joined by a newline (``\\n``)
555         """
--> 556         return "\n".join(self.lines())
557
558     def dump(self, filename, encoding="utf8"):

~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/qiskit/visualization/text.py in lines(self, line_length)
590
591         try:
--> 592             layers = self.build_layers()
593         except TextDrawerCregBundle:
594             self.cregbundle = False

~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/qiskit/visualization/text.py in build_layers(self)
1061             VisualizationError: When the drawing is, for some reason, impossible to be drawn.
1062         """
-> 1063         wire_names = self.wire_names(with_initial_state=self.initial_state)
1064         if not wire_names:
1065             return []

~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/qiskit/visualization/text.py in wire_names(self, with_initial_state)
664             for bit in self.qregs:
665                 label = '{name}_{index} -> {physical} ' + initial_qubit_value
--> 666                 qubit_labels.append(label.format(name=self.layout[bit.index].register.name,
667                                                  index=self.layout[bit.index].index,
668                                                  physical=bit.index))

AttributeError: 'NoneType' object has no attribute 'register'

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
343             method = get_real_method(obj, self.print_method)
344             if method is not None:
--> 345                 return method()
346             return None
347         else:

~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/qiskit/visualization/text.py in _repr_html_(self)
543                'line-height: 1.1;' \
544                'font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace">' \
--> 545                '%s</pre>' % self.single_string()
546
547     def __repr__(self):

~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/qiskit/visualization/text.py in single_string(self)
554             str: The lines joined by a newline (``\\n``)
555         """
--> 556         return "\n".join(self.lines())
557
558     def dump(self, filename, encoding="utf8"):

~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/qiskit/visualization/text.py in lines(self, line_length)
590
591         try:
--> 592             layers = self.build_layers()
593         except TextDrawerCregBundle:
594             self.cregbundle = False

~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/qiskit/visualization/text.py in build_layers(self)
1061             VisualizationError: When the drawing is, for some reason, impossible to be drawn.
1062         """
-> 1063         wire_names = self.wire_names(with_initial_state=self.initial_state)
1064         if not wire_names:
1065             return []

~/anaconda3/envs/new-qiskit/lib/python3.7/site-packages/qiskit/visualization/text.py in wire_names(self, with_initial_state)
664             for bit in self.qregs:
665                 label = '{name}_{index} -> {physical} ' + initial_qubit_value
--> 666                 qubit_labels.append(label.format(name=self.layout[bit.index].register.name,
667                                                  index=self.layout[bit.index].index,
668                                                  physical=bit.index))

AttributeError: 'NoneType' object has no attribute 'register'

# Fixed code
def wire_names(self, with_initial_state=False):
    """Returns a list of names for each wire.

    Args:
        with_initial_state (bool): Optional (Default: False). If true, adds
            the initial value to the name.

    Returns:
        List: The list of wire names.
    """
    if with_initial_state:
        initial_qubit_value = "|0>"
        initial_clbit_value = "0 "
    else:
        initial_qubit_value = ""
        initial_clbit_value = ""

    qubit_labels = []
    if self.layout is None:
        for bit in self.qregs:
            label = "{name}_{index}: " + initial_qubit_value
            qubit_labels.append(
                label.format(name=bit.register.name, index=bit.index, physical="")
            )
    else:
        for bit in self.qregs:
            if self.layout[bit.index]:
                label = "{name}_{index} -> {physical} " + initial_qubit_value
                qubit_labels.append(
                    label.format(
                        name=self.layout[bit.index].register.name,
                        index=self.layout[bit.index].index,
                        physical=bit.index,
                    )
                )
            else:
                qubit_labels.append("%s " % bit.index + initial_qubit_value)

    clbit_labels = []
    previous_creg = None
    for bit in self.cregs:
        if self.cregbundle:
            if previous_creg == bit.register:
                continue
            previous_creg = bit.register
            label = "{name}: {initial_value}{size}/"
            clbit_labels.append(
                label.format(
                    name=bit.register.name,
                    initial_value=initial_clbit_value,
                    size=bit.register.size,
                )
            )
        else:
            label = "{name}_{index}: " + initial_clbit_value
            clbit_labels.append(label.format(name=bit.register.name, index=bit.index))
    return qubit_labels + clbit_labels