Skip to content

Commit e8d4d38

Browse files
committed
pycharm lint, isort & black
1 parent 9f1514a commit e8d4d38

File tree

9 files changed

+169
-113
lines changed

9 files changed

+169
-113
lines changed

uncompyle6/parsers/parse24.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
spark grammar differences over Python2.5 for Python 2.4.
44
"""
55

6-
from uncompyle6.parser import PythonParserSingle
76
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
7+
8+
from uncompyle6.parser import PythonParserSingle
89
from uncompyle6.parsers.parse25 import Python25Parser
910

11+
1012
class Python24Parser(Python25Parser):
1113
def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG):
1214
super(Python24Parser, self).__init__(debug_parser)
1315
self.customized = {}
1416

1517
def p_misc24(self, args):
16-
'''
18+
"""
1719
# Python 2.4 only adds something like the below for if 1:
18-
# However we will just treat it as a noop (which of course messes up
20+
# However we will just treat it as a noop which messes up
1921
# simple verify of bytecode.
2022
# See also below in reduce_is_invalid where we check that the JUMP_FORWARD
2123
# target matches the COME_FROM target
@@ -69,16 +71,18 @@ def p_misc24(self, args):
6971
# Python 2.3- use kv
7072
kvlist ::= kvlist kv2
7173
kv2 ::= DUP_TOP expr expr ROT_THREE STORE_SUBSCR
72-
'''
74+
"""
7375

7476
def remove_rules_24(self):
75-
self.remove_rules("""
77+
self.remove_rules(
78+
"""
7679
expr ::= if_exp
77-
""")
78-
80+
"""
81+
)
7982

8083
def customize_grammar_rules(self, tokens, customize):
81-
self.remove_rules("""
84+
self.remove_rules(
85+
"""
8286
gen_comp_body ::= expr YIELD_VALUE POP_TOP
8387
kvlist ::= kvlist kv3
8488
while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM
@@ -91,44 +95,49 @@ def customize_grammar_rules(self, tokens, customize):
9195
with ::= expr setupwith SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM with_cleanup
9296
stmt ::= with
9397
stmt ::= withasstmt
94-
""")
98+
"""
99+
)
95100
super(Python24Parser, self).customize_grammar_rules(tokens, customize)
96101
self.remove_rules_24()
97102
if self.version[:2] == (2, 4):
98-
self.check_reduce['nop_stmt'] = 'tokens'
103+
self.check_reduce["nop_stmt"] = "tokens"
99104

100105
if self.version[:2] <= (2, 4):
101106
# TODO: We may add something different or customize something
102107
del self.reduce_check_table["ifelsestmt"]
103108

104109
def reduce_is_invalid(self, rule, ast, tokens, first, last):
105-
invalid = super(Python24Parser,
106-
self).reduce_is_invalid(rule, ast,
107-
tokens, first, last)
110+
invalid = super(Python24Parser, self).reduce_is_invalid(
111+
rule, ast, tokens, first, last
112+
)
108113
if invalid or tokens is None:
109114
return invalid
110115

111116
lhs = rule[0]
112-
if lhs == 'nop_stmt':
117+
if lhs == "nop_stmt":
113118
l = len(tokens)
114119
if 0 <= l < len(tokens):
115120
return not int(tokens[first].pattr) == tokens[last].offset
116-
elif lhs == 'try_except':
121+
elif lhs == "try_except":
117122
if last == len(tokens):
118123
last -= 1
119-
if tokens[last] != 'COME_FROM' and tokens[last-1] == 'COME_FROM':
124+
if tokens[last] != "COME_FROM" and tokens[last - 1] == "COME_FROM":
120125
last -= 1
121-
return (tokens[last] == 'COME_FROM'
122-
and tokens[last-1] == 'END_FINALLY'
123-
and tokens[last-2] == 'POP_TOP'
124-
and tokens[last-3].kind != 'JUMP_FORWARD')
126+
return (
127+
tokens[last] == "COME_FROM"
128+
and tokens[last - 1] == "END_FINALLY"
129+
and tokens[last - 2] == "POP_TOP"
130+
and tokens[last - 3].kind != "JUMP_FORWARD"
131+
)
125132

126133
return False
127134

135+
128136
class Python24ParserSingle(Python24Parser, PythonParserSingle):
129137
pass
130138

131-
if __name__ == '__main__':
139+
140+
if __name__ == "__main__":
132141
# Check grammar
133142
p = Python24Parser()
134143
p.check_grammar()

uncompyle6/parsers/parse25.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
spark grammar differences over Python2.6 for Python 2.5.
44
"""
55

6-
from uncompyle6.parser import PythonParserSingle
76
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
7+
8+
from uncompyle6.parser import PythonParserSingle
89
from uncompyle6.parsers.parse26 import Python26Parser
9-
from uncompyle6.parsers.reducecheck import (ifelsestmt)
10+
from uncompyle6.parsers.reducecheck import ifelsestmt
11+
1012

1113
class Python25Parser(Python26Parser):
1214
def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG):
@@ -60,7 +62,8 @@ def p_misc25(self, args):
6062

6163
def customize_grammar_rules(self, tokens, customize):
6264
# Remove grammar rules inherited from Python 2.6 or Python 2
63-
self.remove_rules("""
65+
self.remove_rules(
66+
"""
6467
setupwith ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 POP_TOP
6568
with ::= expr setupwith SETUP_FINALLY suite_stmts_opt
6669
POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY
@@ -87,17 +90,18 @@ def customize_grammar_rules(self, tokens, customize):
8790
return_stmt_lambda LAMBDA_MARKER
8891
if_exp_not_lambda ::= expr jmp_true_then expr return_if_lambda
8992
return_stmt_lambda LAMBDA_MARKER
90-
""")
93+
"""
94+
)
9195
super(Python25Parser, self).customize_grammar_rules(tokens, customize)
9296
if self.version[:2] == (2, 5):
9397
self.check_reduce["try_except"] = "AST"
9498
self.check_reduce["aug_assign1"] = "AST"
9599
self.check_reduce["ifelsestmt"] = "AST"
96100

97101
def reduce_is_invalid(self, rule, ast, tokens, first, last):
98-
invalid = super(Python25Parser,
99-
self).reduce_is_invalid(rule, ast,
100-
tokens, first, last)
102+
invalid = super(Python25Parser, self).reduce_is_invalid(
103+
rule, ast, tokens, first, last
104+
)
101105
if invalid or tokens is None:
102106
return invalid
103107
if rule == ("aug_assign1", ("expr", "expr", "inplace_op", "store")):
@@ -112,6 +116,7 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last):
112116
class Python25ParserSingle(Python26Parser, PythonParserSingle):
113117
pass
114118

119+
115120
if __name__ == "__main__":
116121
# Check grammar
117122
p = Python25Parser()

uncompyle6/parsers/parse26.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
spark grammar differences over Python2 for Python 2.6.
44
"""
55

6-
from uncompyle6.parser import PythonParserSingle
76
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
7+
8+
from uncompyle6.parser import PythonParserSingle
89
from uncompyle6.parsers.parse2 import Python2Parser
910
from uncompyle6.parsers.reducecheck import (
1011
except_handler,
1112
ifelsestmt2,
1213
ifstmt2,
13-
tryexcept,
1414
tryelsestmt,
15+
tryexcept,
1516
)
1617

1718

@@ -64,8 +65,8 @@ def p_try_except26(self, args):
6465
except_suite ::= c_stmts_opt jmp_abs come_from_pop
6566
6667
# This is what happens after a jump where
67-
# we start a new block. For reasons I don't fully
68-
# understand, there is also a value on the top of the stack
68+
# we start a new block. For reasons that I don't fully
69+
# understand, there is also a value on the top of the stack.
6970
come_from_pop ::= COME_FROM POP_TOP
7071
come_froms_pop ::= come_froms POP_TOP
7172
"""
@@ -78,7 +79,7 @@ def p_try_except26(self, args):
7879
def p_jumps26(self, args):
7980
"""
8081
81-
# The are the equivalents of Python 2.7+'s
82+
# There are the equivalents of Python 2.7+'s
8283
# POP_JUMP_IF_TRUE and POP_JUMP_IF_FALSE
8384
jmp_true ::= JUMP_IF_TRUE POP_TOP
8485
jmp_false ::= JUMP_IF_FALSE POP_TOP
@@ -106,8 +107,8 @@ def p_jumps26(self, args):
106107
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD come_froms POP_TOP COME_FROM
107108
108109
# This is what happens after a jump where
109-
# we start a new block. For reasons I don't fully
110-
# understand, there is also a value on the top of the stack
110+
# we start a new block. For reasons that I don't fully
111+
# understand, there is also a value on the top of the stack.
111112
come_froms_pop ::= come_froms POP_TOP
112113
113114
"""
@@ -394,7 +395,7 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last):
394395
if ast[1] is None:
395396
return False
396397

397-
# For now, we won't let the 2nd 'expr' be a "if_exp_not"
398+
# For now, we won't let the 2nd 'expr' be an "if_exp_not"
398399
# However in < 2.6 where we don't have if/else expression it *can*
399400
# be.
400401
if self.version >= (2, 6) and ast[2][0] == "if_exp_not":
@@ -464,7 +465,7 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last):
464465
ja_attr = ast[4].attr
465466
return tokens[last].offset != ja_attr
466467
elif lhs == "try_except":
467-
# We need to distingush try_except from tryelsestmt and we do that
468+
# We need to distingush "try_except" from "tryelsestmt"; we do that
468469
# by checking the jump before the END_FINALLY
469470
# If we have:
470471
# insn
@@ -490,7 +491,7 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last):
490491
) or (tokens[last - 3] == "JUMP_FORWARD" and tokens[last - 3].attr != 2)
491492
elif lhs == "tryelsestmt":
492493

493-
# We need to distingush try_except from tryelsestmt and we do that
494+
# We need to distinguish "try_except" from "tryelsestmt"; we do that
494495
# by making sure that the jump before the except handler jumps to
495496
# code somewhere before the end of the construct.
496497
# This AST method is slower, but the token-only based approach
@@ -508,8 +509,8 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last):
508509
return else_start >= last_offset
509510

510511
# The above test apparently isn't good enough, so we have additional
511-
# checks distinguish try_except from tryelsestmt and we do that
512-
# by checking the jump before the END_FINALLY
512+
# checks distinguish "try_except" from "tryelsestmt". we do that
513+
# by checking the jump before the "END_FINALLY".
513514
# If we have:
514515
# insn
515516
# POP_TOP
@@ -546,7 +547,7 @@ class Python26ParserSingle(Python2Parser, PythonParserSingle):
546547
# Check grammar
547548
p = Python26Parser()
548549
p.check_grammar()
549-
from xdis.version_info import PYTHON_VERSION_TRIPLE, IS_PYPY
550+
from xdis.version_info import IS_PYPY, PYTHON_VERSION_TRIPLE
550551

551552
if PYTHON_VERSION_TRIPLE[:2] == (2, 6):
552553
lhs, rhs, tokens, right_recursive, dup_rhs = p.check_sets()

0 commit comments

Comments
 (0)