

def _find_parenthesis(self, position, forward=True):
    " If 'forward' is True (resp. False), proceed forwards\n            (resp. backwards) through the line that contains 'position' until an\n            unmatched closing (resp. opening) parenthesis is found. Returns a\n            tuple containing the position of this parenthesis (or -1 if it is\n            not found) and the number commas (at depth 0) found along the way.\n        "
    commas = depth = 0
    document = self._text_edit.document()
    char = document.characterAt(position)
    while ((category(char) != 'Cc') and (position > 0)):
        if ((char == ',') and (depth == 0)):
            commas += 1
        elif (char == ')'):
            if (forward and (depth == 0)):
                break
            depth += 1
        elif (char == '('):
            if ((not forward) and (depth == 0)):
                break
            depth -= 1
        position += (1 if forward else (- 1))
        char = document.characterAt(position)
    else:
        position = (- 1)
    return (position, commas)

dataset/ETHPy150Open enthought/pyface/pyface/ui/qt4/console/call_tip_widget.py CallTipWidget._find_parenthesis/original