

def strip_parens(s):
    if ((not s) or (s[0] != '(')):
        return s
    ct = i = 0
    l = len(s)
    while (i < l):
        if ((s[i] == '(') and (s[(l - 1)] == ')')):
            ct += 1
            i += 1
            l -= 1
        else:
            break
    if ct:
        unbalanced_ct = 0
        required = 0
        for i in range(ct, (l - ct)):
            if (s[i] == '('):
                unbalanced_ct += 1
            elif (s[l] == ')'):
                unbalanced_ct -= 1
            if (unbalanced_ct < 0):
                required += 1
                unbalanced_ct = 0
            if (required == ct):
                break
        ct -= required
    if (ct > 0):
        return s[ct:(- ct)]
    return s

dataset/ETHPy150Open coleifer/peewee/peewee.py strip_parens/VarMisuse@153/171 `i`->`l`