1
- # Copyright (c) 2019-2022 by Rocky Bernstein
1
+ # Copyright (c) 2019-2023 by Rocky Bernstein
2
2
#
3
3
# This program is free software: you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
"""
17
17
18
18
import re
19
- from uncompyle6 .semantics .consts import (
20
- PRECEDENCE ,
21
- TABLE_DIRECT ,
22
- INDENT_PER_LEVEL ,
23
- )
24
19
20
+ from uncompyle6 .semantics .consts import INDENT_PER_LEVEL , PRECEDENCE , TABLE_DIRECT
25
21
from uncompyle6 .semantics .helper import flatten_list
26
22
27
23
FSTRING_CONVERSION_MAP = {1 : "!s" , 2 : "!r" , 3 : "!a" , "X" : ":X" }
@@ -54,10 +50,13 @@ def customize_for_version37(self, version):
54
50
{
55
51
"and_not" : ("%c and not %c" , (0 , "expr" ), (2 , "expr" )),
56
52
"ann_assign" : (
57
- "%|%[2]{attr}: %c\n " , 0 ,
53
+ "%|%[2]{attr}: %c\n " ,
54
+ 0 ,
58
55
),
59
56
"ann_assign_init" : (
60
- "%|%[2]{attr}: %c = %c\n " , 0 , 1 ,
57
+ "%|%[2]{attr}: %c = %c\n " ,
58
+ 0 ,
59
+ 1 ,
61
60
),
62
61
"async_for_stmt" : (
63
62
"%|async for %c in %c:\n %+%c%-\n \n " ,
@@ -89,9 +88,8 @@ def customize_for_version37(self, version):
89
88
"attributes37" : (
90
89
"%[0]{pattr} import %c" ,
91
90
(0 , "IMPORT_NAME_ATTR" ),
92
- (1 , "IMPORT_FROM" )
91
+ (1 , "IMPORT_FROM" ),
93
92
),
94
-
95
93
# nested await expressions like:
96
94
# return await (await bar())
97
95
# need parenthesis.
@@ -126,19 +124,24 @@ def customize_for_version37(self, version):
126
124
(0 , PRECEDENCE ["compare" ] - 1 ),
127
125
(- 2 , PRECEDENCE ["compare" ] - 1 ),
128
126
),
129
- "compare_chained2a_37" : ('%[1]{pattr.replace("-", " ")} %p' , (0 , PRECEDENCE ["compare" ] - 1 )),
130
- "compare_chained2b_false_37" : ('%[1]{pattr.replace("-", " ")} %p' , (0 , PRECEDENCE ["compare" ] - 1 )),
131
- "compare_chained2a_false_37" : ('%[1]{pattr.replace("-", " ")} %p' , (0 , PRECEDENCE ["compare" ] - 1 )),
127
+ "compare_chained2a_37" : (
128
+ '%[1]{pattr.replace("-", " ")} %p' ,
129
+ (0 , PRECEDENCE ["compare" ] - 1 ),
130
+ ),
131
+ "compare_chained2b_false_37" : (
132
+ '%[1]{pattr.replace("-", " ")} %p' ,
133
+ (0 , PRECEDENCE ["compare" ] - 1 ),
134
+ ),
135
+ "compare_chained2a_false_37" : (
136
+ '%[1]{pattr.replace("-", " ")} %p' ,
137
+ (0 , PRECEDENCE ["compare" ] - 1 ),
138
+ ),
132
139
"compare_chained2c_37" : (
133
140
'%[3]{pattr.replace("-", " ")} %p %p' ,
134
141
(0 , PRECEDENCE ["compare" ] - 1 ),
135
142
(6 , PRECEDENCE ["compare" ] - 1 ),
136
143
),
137
- 'if_exp37' : (
138
- '%p if %c else %c' ,
139
- (1 , 'expr' , 27 ), 0 , 3
140
- ),
141
-
144
+ "if_exp37" : ("%p if %c else %c" , (1 , "expr" , 27 ), 0 , 3 ),
142
145
"except_return" : ("%|except:\n %+%c%-" , 3 ),
143
146
"if_exp_37a" : (
144
147
"%p if %p else %p" ,
@@ -153,9 +156,7 @@ def customize_for_version37(self, version):
153
156
(5 , "expr" , 27 ),
154
157
),
155
158
"ifstmtl" : ("%|if %c:\n %+%c%-" , (0 , "testexpr" ), (1 , "_ifstmts_jumpl" )),
156
- 'import_as37' : (
157
- "%|import %c as %c\n " , 2 , - 2
158
- ),
159
+ "import_as37" : ("%|import %c as %c\n " , 2 , - 2 ),
159
160
"import_from37" : ("%|from %[2]{pattr} import %c\n " , (3 , "importlist37" )),
160
161
"import_from_as37" : (
161
162
"%|from %c as %c\n " ,
@@ -178,12 +179,11 @@ def customize_for_version37(self, version):
178
179
(0 , "get_aiter" ),
179
180
(3 , "list_iter" ),
180
181
),
181
-
182
182
"list_if37" : (" if %p%c" , (0 , 27 ), 1 ),
183
183
"list_if37_not" : (" if not %p%c" , (0 , 27 ), 1 ),
184
184
"testfalse_not_or" : ("not %c or %c" , (0 , "expr" ), (2 , "expr" )),
185
185
"testfalse_not_and" : ("not (%c)" , 0 ),
186
- "testfalsel" : ("not %c" , (0 , "expr" )),
186
+ "testfalsel" : ("not %c" , (0 , "expr" )),
187
187
"try_except36" : ("%|try:\n %+%c%-%c\n \n " , 1 , - 2 ),
188
188
"tryfinally36" : ("%|try:\n %+%c%-%|finally:\n %+%c%-\n \n " , (1 , "returns" ), 3 ),
189
189
"dict_unpack" : ("{**%C}" , (0 , - 1 , ", **" )),
0 commit comments