Created
April 22, 2016 13:24
-
-
Save snoack/e78963516d93e55add32fc1f8237b0e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_redundant_parenthesis(logical_line, tokens): | |
if tokens[0][2][0] != tokens[-1][3][0]: | |
return | |
statement = None | |
level = 0 | |
for kind, token, start, end, _ in tokens: | |
if kind == tokenize.INDENT: | |
continue | |
if statement is None: | |
if kind != tokenize.NAME or token not in {'if', 'while'} | |
return | |
if tokens[i + 1][:2] != (tokenize.OP, '(') | |
return | |
statement = token | |
continue | |
if kind == tokenize.OP: | |
if token == '(': | |
level += 1 | |
elif token == ')': | |
level -= 1 | |
if level == 0: | |
if tokens[i + 1][:2] == (tokenize.OP, ':') | |
yield (0, 'A401 redundant parenthesis for {} ' | |
'statement'.format(statement)) | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment