Skip to content

Commit 190c068

Browse files
committed
withasstmt -> with_as
Matches AST a little closer and is not as confusing a name
1 parent 755c16f commit 190c068

File tree

11 files changed

+73
-50
lines changed

11 files changed

+73
-50
lines changed

decompyle3/parsers/p37/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ def customize_grammar_rules37(self, tokens, customize):
10041004
rules_str = """
10051005
stmt ::= with
10061006
stmt ::= with_as_pass
1007-
stmt ::= withasstmt
1007+
stmt ::= with_as
10081008
c_stmt ::= c_with
10091009
10101010
c_with ::= expr SETUP_WITH POP_TOP
@@ -1021,14 +1021,14 @@ def customize_grammar_rules37(self, tokens, customize):
10211021
COME_FROM_WITH
10221022
with_suffix
10231023
1024-
withasstmt ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
1024+
with_as ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
10251025
with_suffix
10261026
10271027
with ::= expr
10281028
SETUP_WITH POP_TOP suite_stmts_opt
10291029
POP_BLOCK LOAD_CONST COME_FROM_WITH
10301030
with_suffix
1031-
withasstmt ::= expr
1031+
with_as ::= expr
10321032
SETUP_WITH store suite_stmts_opt
10331033
POP_BLOCK LOAD_CONST COME_FROM_WITH
10341034
with_suffix
@@ -1037,7 +1037,7 @@ def customize_grammar_rules37(self, tokens, customize):
10371037
SETUP_WITH POP_TOP suite_stmts_opt
10381038
POP_BLOCK LOAD_CONST COME_FROM_WITH
10391039
with_suffix
1040-
withasstmt ::= expr
1040+
with_as ::= expr
10411041
SETUP_WITH store suite_stmts_opt
10421042
POP_BLOCK LOAD_CONST COME_FROM_WITH
10431043
with_suffix
@@ -1067,16 +1067,16 @@ def customize_grammar_rules37(self, tokens, customize):
10671067
with_suffix
10681068
10691069
1070-
withasstmt ::= expr
1070+
with_as ::= expr
10711071
SETUP_WITH store suite_stmts
10721072
POP_BLOCK LOAD_CONST COME_FROM_WITH
10731073
1074-
withasstmt ::= expr
1074+
with_as ::= expr
10751075
SETUP_WITH store suite_stmts
10761076
POP_BLOCK BEGIN_FINALLY COME_FROM_WITH
10771077
with_suffix
10781078
1079-
# withasstmt ::= expr SETUP_WITH store suite_stmts
1079+
# with_as ::= expr SETUP_WITH store suite_stmts
10801080
# COME_FROM expr COME_FROM POP_BLOCK ROT_TWO
10811081
# BEGIN_FINALLY WITH_CLEANUP_START WITH_CLEANUP_FINISH
10821082
# POP_FINALLY RETURN_VALUE COME_FROM_WITH

decompyle3/parsers/p37/lambda_custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ def customize_grammar_rules_lambda37(self, tokens, customize):
542542
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
543543
544544
# Removes POP_BLOCK LOAD_CONST from 3.6-
545-
withasstmt ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
545+
with_as ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
546546
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
547547
"""
548548
if self.version < (3, 8):

decompyle3/parsers/p38/full_custom.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ def customize_grammar_rules_full38(self, tokens, customize):
661661
rules_str = """
662662
stmt ::= with
663663
stmt ::= with_as_pass
664-
stmt ::= withasstmt
664+
stmt ::= with_as
665665
666666
c_stmt ::= c_with
667667
@@ -679,23 +679,25 @@ def customize_grammar_rules_full38(self, tokens, customize):
679679
COME_FROM_WITH
680680
with_suffix
681681
682-
withasstmt ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
682+
with ::= expr
683+
SETUP_WITH POP_TOP suite_stmts_opt
684+
POP_BLOCK LOAD_CONST COME_FROM_WITH
683685
with_suffix
684686
685687
with ::= expr
686688
SETUP_WITH POP_TOP suite_stmts_opt
687689
POP_BLOCK LOAD_CONST COME_FROM_WITH
688690
with_suffix
689-
withasstmt ::= expr
691+
692+
with_as ::= expr
690693
SETUP_WITH store suite_stmts_opt
691694
POP_BLOCK LOAD_CONST COME_FROM_WITH
692695
with_suffix
693696
694-
with ::= expr
695-
SETUP_WITH POP_TOP suite_stmts_opt
696-
POP_BLOCK LOAD_CONST COME_FROM_WITH
697+
with_as ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
697698
with_suffix
698-
withasstmt ::= expr
699+
700+
with_as ::= expr
699701
SETUP_WITH store suite_stmts_opt
700702
POP_BLOCK LOAD_CONST COME_FROM_WITH
701703
with_suffix
@@ -729,16 +731,16 @@ def customize_grammar_rules_full38(self, tokens, customize):
729731
with_suffix
730732
731733
732-
withasstmt ::= expr
734+
with_as ::= expr
733735
SETUP_WITH store suite_stmts
734736
POP_BLOCK LOAD_CONST COME_FROM_WITH
735737
736-
withasstmt ::= expr
738+
with_as ::= expr
737739
SETUP_WITH store suite_stmts
738740
POP_BLOCK BEGIN_FINALLY COME_FROM_WITH
739741
with_suffix
740742
741-
# withasstmt ::= expr SETUP_WITH store suite_stmts
743+
# with_as ::= expr SETUP_WITH store suite_stmts
742744
# COME_FROM expr COME_FROM POP_BLOCK ROT_TWO
743745
# BEGIN_FINALLY WITH_CLEANUP_START WITH_CLEANUP_FINISH
744746
# POP_FINALLY RETURN_VALUE COME_FROM_WITH
@@ -1229,7 +1231,7 @@ def customize_grammar_rules38(self, tokens, customize):
12291231
elif opname == "SETUP_WITH":
12301232
rules_str = """
12311233
stmt ::= with
1232-
stmt ::= withasstmt
1234+
stmt ::= with_as
12331235
c_stmt ::= c_with
12341236
12351237
c_with ::= expr SETUP_WITH POP_TOP
@@ -1246,14 +1248,14 @@ def customize_grammar_rules38(self, tokens, customize):
12461248
COME_FROM_WITH
12471249
with_suffix
12481250
1249-
withasstmt ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
1251+
with_as ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
12501252
with_suffix
12511253
12521254
with ::= expr
12531255
SETUP_WITH POP_TOP suite_stmts_opt
12541256
POP_BLOCK LOAD_CONST COME_FROM_WITH
12551257
with_suffix
1256-
withasstmt ::= expr
1258+
with_as ::= expr
12571259
SETUP_WITH store suite_stmts_opt
12581260
POP_BLOCK LOAD_CONST COME_FROM_WITH
12591261
with_suffix
@@ -1262,7 +1264,7 @@ def customize_grammar_rules38(self, tokens, customize):
12621264
SETUP_WITH POP_TOP suite_stmts_opt
12631265
POP_BLOCK LOAD_CONST COME_FROM_WITH
12641266
with_suffix
1265-
withasstmt ::= expr
1267+
with_as ::= expr
12661268
SETUP_WITH store suite_stmts_opt
12671269
POP_BLOCK LOAD_CONST COME_FROM_WITH
12681270
with_suffix
@@ -1291,16 +1293,16 @@ def customize_grammar_rules38(self, tokens, customize):
12911293
with_suffix
12921294
12931295
1294-
withasstmt ::= expr
1296+
with_as ::= expr
12951297
SETUP_WITH store suite_stmts
12961298
POP_BLOCK LOAD_CONST COME_FROM_WITH
12971299
1298-
withasstmt ::= expr
1300+
with_as ::= expr
12991301
SETUP_WITH store suite_stmts
13001302
POP_BLOCK BEGIN_FINALLY COME_FROM_WITH
13011303
with_suffix
13021304
1303-
# withasstmt ::= expr SETUP_WITH store suite_stmts
1305+
# with_as ::= expr SETUP_WITH store suite_stmts
13041306
# COME_FROM expr COME_FROM POP_BLOCK ROT_TWO
13051307
# BEGIN_FINALLY WITH_CLEANUP_START WITH_CLEANUP_FINISH
13061308
# POP_FINALLY RETURN_VALUE COME_FROM_WITH

decompyle3/parsers/p38/lambda_custom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ def customize_grammar_rules_lambda38(self, tokens, customize):
612612
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
613613
614614
# Removes POP_BLOCK LOAD_CONST from 3.6-
615-
withasstmt ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
616-
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
615+
with_as ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
616+
a WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
617617
"""
618618
if self.version < (3, 8):
619619
rules_str += """

decompyle3/parsers/p38pypy/full_custom.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def customize_grammar_rules_full38(self, tokens, customize):
660660
elif opname == "SETUP_WITH":
661661
rules_str = """
662662
stmt ::= with
663-
stmt ::= withasstmt
663+
stmt ::= with_as
664664
c_stmt ::= c_with
665665
666666
c_with ::= expr SETUP_WITH POP_TOP
@@ -677,14 +677,14 @@ def customize_grammar_rules_full38(self, tokens, customize):
677677
COME_FROM_WITH
678678
with_suffix
679679
680-
withasstmt ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
680+
with_as ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
681681
with_suffix
682682
683683
with ::= expr
684684
SETUP_WITH POP_TOP suite_stmts_opt
685685
POP_BLOCK LOAD_CONST COME_FROM_WITH
686686
with_suffix
687-
withasstmt ::= expr
687+
with_as ::= expr
688688
SETUP_WITH store suite_stmts_opt
689689
POP_BLOCK LOAD_CONST COME_FROM_WITH
690690
with_suffix
@@ -693,7 +693,7 @@ def customize_grammar_rules_full38(self, tokens, customize):
693693
SETUP_WITH POP_TOP suite_stmts_opt
694694
POP_BLOCK LOAD_CONST COME_FROM_WITH
695695
with_suffix
696-
withasstmt ::= expr
696+
with_as ::= expr
697697
SETUP_WITH store suite_stmts_opt
698698
POP_BLOCK LOAD_CONST COME_FROM_WITH
699699
with_suffix
@@ -722,16 +722,16 @@ def customize_grammar_rules_full38(self, tokens, customize):
722722
with_suffix
723723
724724
725-
withasstmt ::= expr
725+
with_as ::= expr
726726
SETUP_WITH store suite_stmts
727727
POP_BLOCK LOAD_CONST COME_FROM_WITH
728728
729-
withasstmt ::= expr
729+
with_as ::= expr
730730
SETUP_WITH store suite_stmts
731731
POP_BLOCK BEGIN_FINALLY COME_FROM_WITH
732732
with_suffix
733733
734-
# withasstmt ::= expr SETUP_WITH store suite_stmts
734+
# with_as ::= expr SETUP_WITH store suite_stmts
735735
# COME_FROM expr COME_FROM POP_BLOCK ROT_TWO
736736
# BEGIN_FINALLY WITH_CLEANUP_START WITH_CLEANUP_FINISH
737737
# POP_FINALLY RETURN_VALUE COME_FROM_WITH
@@ -1222,7 +1222,7 @@ def customize_grammar_rules38(self, tokens, customize):
12221222
elif opname == "SETUP_WITH":
12231223
rules_str = """
12241224
stmt ::= with
1225-
stmt ::= withasstmt
1225+
stmt ::= with_as
12261226
c_stmt ::= c_with
12271227
12281228
c_with ::= expr SETUP_WITH POP_TOP
@@ -1239,14 +1239,14 @@ def customize_grammar_rules38(self, tokens, customize):
12391239
COME_FROM_WITH
12401240
with_suffix
12411241
1242-
withasstmt ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
1242+
with_as ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
12431243
with_suffix
12441244
12451245
with ::= expr
12461246
SETUP_WITH POP_TOP suite_stmts_opt
12471247
POP_BLOCK LOAD_CONST COME_FROM_WITH
12481248
with_suffix
1249-
withasstmt ::= expr
1249+
with_as ::= expr
12501250
SETUP_WITH store suite_stmts_opt
12511251
POP_BLOCK LOAD_CONST COME_FROM_WITH
12521252
with_suffix
@@ -1255,7 +1255,7 @@ def customize_grammar_rules38(self, tokens, customize):
12551255
SETUP_WITH POP_TOP suite_stmts_opt
12561256
POP_BLOCK LOAD_CONST COME_FROM_WITH
12571257
with_suffix
1258-
withasstmt ::= expr
1258+
with_as ::= expr
12591259
SETUP_WITH store suite_stmts_opt
12601260
POP_BLOCK LOAD_CONST COME_FROM_WITH
12611261
with_suffix
@@ -1284,20 +1284,20 @@ def customize_grammar_rules38(self, tokens, customize):
12841284
with_suffix
12851285
12861286
1287-
withasstmt ::= expr
1287+
with_as ::= expr
12881288
SETUP_WITH store suite_stmts
12891289
POP_BLOCK LOAD_CONST COME_FROM_WITH
12901290
1291-
withasstmt ::= expr
1291+
with_as ::= expr
12921292
SETUP_WITH store suite_stmts
12931293
POP_BLOCK BEGIN_FINALLY COME_FROM_WITH
12941294
with_suffix
12951295
1296-
# withasstmt ::= expr SETUP_WITH store suite_stmts
1297-
# COME_FROM expr COME_FROM POP_BLOCK ROT_TWO
1298-
# BEGIN_FINALLY WITH_CLEANUP_START WITH_CLEANUP_FINISH
1299-
# POP_FINALLY RETURN_VALUE COME_FROM_WITH
1300-
# WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
1296+
# with_as ::= expr SETUP_WITH store suite_stmts
1297+
# COME_FROM expr COME_FROM POP_BLOCK ROT_TWO
1298+
# BEGIN_FINALLY WITH_CLEANUP_START WITH_CLEANUP_FINISH
1299+
# POP_FINALLY RETURN_VALUE COME_FROM_WITH
1300+
# WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
13011301
13021302
with ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK
13031303
BEGIN_FINALLY COME_FROM_WITH

decompyle3/parsers/p38pypy/lambda_custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ def customize_grammar_rules_lambda38(self, tokens, customize):
623623
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
624624
625625
# Removes POP_BLOCK LOAD_CONST from 3.6-
626-
withasstmt ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
626+
with_as ::= expr SETUP_WITH store suite_stmts_opt COME_FROM_WITH
627627
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
628628
"""
629629
if self.version < (3, 8):

decompyle3/semantics/consts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,12 @@
577577
"import_from_star": ("%|from %[2]{pattr} import *\n",),
578578

579579
# If there are situations where we need "with ... as ()"
580-
# We may need to customize this in n_withasstmt
581-
"withasstmt": (
580+
# We may need to customize this in n_with_as
581+
"with_as": (
582582
"%|with %c as %c:\n%+%c%-",
583583
(0, "expr"),
584584
(2, "store"),
585-
(3, "suite_stmts_opt"),
585+
(3, ("suite_stmts_opt", "_stmts")),
586586
),
587587

588588
}

decompyle3/semantics/transform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
# "return_expr",
6868
# "set_comp_func",
6969
"tryfinallystmt",
70-
"withasstmt",
70+
"with_as",
7171
)
7272

7373

843 Bytes
Binary file not shown.
852 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)