(span_str, brackets='()')
return nesting > 0
Check if the span ends with an unclosed `bracket`.
Check if the span ends with an unclosed `bracket`.
Check if the span ends with an unclosed bracket .
def _is_open(span_str, brackets='()'):
    """Check if the span ends with an unclosed `bracket`."""
    offset = span_str.find(brackets[0])
    nesting = 0 if offset == -1 else 1

    while offset != -1:
        opener = span_str.find(brackets[0], offset + 1)
        closer = span_str.find(brackets[1], offset + 1)

        if opener == -1:
            if closer == -1:
                offset = -1
            else:
                offset = closer
                nesting -= 1
        elif closer == -1:
            offset = opener
            nesting += 1
        elif opener < closer:
            offset = opener
            nesting += 1
        elif closer < opener:
            offset = closer
            nesting -= 1
        else:
            msg = 'at offset={}: closer={}, opener={}'
            raise RuntimeError(msg.format(offset, closer, opener))

    return nesting > 0
def _is_open ( span_str , brackets = '()' ) : offset = span_str . find ( brackets [ 0 ] ) nesting = 0 if offset == - 1 else 1 while offset != - 1 : opener = span_str . find ( brackets [ 0 ] , offset + 1 ) closer = span_str . find ( brackets [ 1 ] , offset + 1 ) if opener == - 1 : if closer == - 1 : offset = - 1 else : offset = closer nesting -= 1 elif closer == - 1 : offset = opener nesting += 1 elif opener < closer : offset = opener nesting += 1 elif closer < opener : offset = closer nesting -= 1 else : msg = 'at offset={}: closer={}, opener={}' raise RuntimeError ( msg . format ( offset , closer , opener ) ) return nesting > 0