def pin_to_wire_and_idx(pin):
    """ Break pin name into wire name and vector index.

    Arguments
    ---------
    pin : str
        Pin name, with optional vector index.

    Returns
    -------
    wire : str
        Wire name
    idx : int
        Vector index

    >>> pin_to_wire_and_idx('A')
    ('A', None)
    >>> pin_to_wire_and_idx('A[0]')
    ('A', 0)
    >>> pin_to_wire_and_idx('A[1]')
    ('A', 1)

    """
    idx = pin.find('[')
    if idx == -1:
        return (pin, None)
    else:
        assert pin[-1] == ']'
        return (pin[:idx], int(pin[idx + 1:-1]))