1- # Copyright (c) 2018-2019, 2021-2022 by Rocky Bernstein
1+ # Copyright (c) 2018-2019, 2021-2022 2024 by Rocky Bernstein
22#
33# This program is free software: you can redistribute it and/or modify
44# it under the terms of the GNU General Public License as published by
1717"""
1818
1919from uncompyle6 .parsers .treenode import SyntaxTree
20+ from uncompyle6 .scanners .tok import Token
2021from uncompyle6 .semantics .consts import (
2122 INDENT_PER_LEVEL ,
2223 NO_PARENTHESIS_EVER ,
2324 PRECEDENCE ,
24- TABLE_R ,
2525 TABLE_DIRECT ,
26+ TABLE_R ,
2627)
2728from uncompyle6 .semantics .helper import flatten_list
28- from uncompyle6 .scanners .tok import Token
2929
3030
3131def customize_for_version (self , is_pypy , version ):
32+ self .TABLE_DIRECT = TABLE_DIRECT .copy ()
3233 if is_pypy :
3334 ########################
3435 # PyPy changes
3536 #######################
3637 # fmt: off
37- TABLE_DIRECT .update ({
38+ self . TABLE_DIRECT .update ({
3839
3940 "assert" : ("%|assert %c\n " , 0 ),
4041 # This can happen as a result of an if transformation
@@ -114,7 +115,7 @@ def n_call_kw_pypy37(node):
114115 ########################
115116 # Without PyPy
116117 #######################
117- TABLE_DIRECT .update (
118+ self . TABLE_DIRECT .update (
118119 {
119120 # "assert" and "assert_expr" are added via transform rules.
120121 "assert" : ("%|assert %c\n " , 0 ),
@@ -133,23 +134,23 @@ def n_call_kw_pypy37(node):
133134 )
134135 if version >= (3 , 0 ):
135136 if version >= (3 , 2 ):
136- TABLE_DIRECT .update (
137+ self . TABLE_DIRECT .update (
137138 {"del_deref_stmt" : ("%|del %c\n " , 0 ), "DELETE_DEREF" : ("%{pattr}" , 0 )}
138139 )
139140 from uncompyle6 .semantics .customize3 import customize_for_version3
140141
141142 customize_for_version3 (self , version )
142143 else : # < 3.0
143- TABLE_DIRECT .update (
144+ self . TABLE_DIRECT .update (
144145 {"except_cond3" : ("%|except %c, %c:\n " , (1 , "expr" ), (- 2 , "store" ))}
145146 )
146147 if version <= (2 , 6 ):
147- TABLE_DIRECT ["testtrue_then" ] = TABLE_DIRECT ["testtrue" ]
148+ self . TABLE_DIRECT ["testtrue_then" ] = self . TABLE_DIRECT ["testtrue" ]
148149
149150 if (2 , 4 ) <= version <= (2 , 6 ):
150- TABLE_DIRECT .update ({"comp_for" : (" for %c in %c" , 3 , 1 )})
151+ self . TABLE_DIRECT .update ({"comp_for" : (" for %c in %c" , 3 , 1 )})
151152 else :
152- TABLE_DIRECT .update ({"comp_for" : (" for %c in %c%c" , 2 , 0 , 3 )})
153+ self . TABLE_DIRECT .update ({"comp_for" : (" for %c in %c%c" , 2 , 0 , 3 )})
153154
154155 if version >= (2 , 5 ):
155156 from uncompyle6 .semantics .customize25 import customize_for_version25
@@ -197,7 +198,7 @@ def n_call_kw_pypy37(node):
197198 )
198199 ],
199200 )
200- TABLE_DIRECT .update (
201+ self . TABLE_DIRECT .update (
201202 {
202203 "importmultiple" : ("%|import %c%c\n " , 2 , 3 ),
203204 "import_cont" : (", %c" , 2 ),
@@ -247,9 +248,9 @@ def n_call(node):
247248 self .n_call = n_call
248249
249250 else : # 1.0 <= version <= 2.3:
250- TABLE_DIRECT .update ({"if1_stmt" : ("%|if 1\n %+%c%-" , 5 )})
251+ self . TABLE_DIRECT .update ({"if1_stmt" : ("%|if 1\n %+%c%-" , 5 )})
251252 if version <= (2 , 1 ):
252- TABLE_DIRECT .update (
253+ self . TABLE_DIRECT .update (
253254 {
254255 "importmultiple" : ("%c" , 2 ),
255256 # FIXME: not quite right. We have indiividual imports
@@ -263,7 +264,8 @@ def n_call(node):
263264
264265 # < 3.0 continues
265266
266- TABLE_R .update (
267+ self .TABLE_R = TABLE_R .copy ()
268+ self .TABLE_R .update (
267269 {
268270 "STORE_SLICE+0" : ("%c[:]" , 0 ),
269271 "STORE_SLICE+1" : ("%c[%p:]" , 0 , (1 , - 1 )),
@@ -275,7 +277,7 @@ def n_call(node):
275277 "DELETE_SLICE+3" : ("%|del %c[%c:%c]\n " , 0 , 1 , 2 ),
276278 }
277279 )
278- TABLE_DIRECT .update ({"raise_stmt2" : ("%|raise %c, %c\n " , 0 , 1 )})
280+ self . TABLE_DIRECT .update ({"raise_stmt2" : ("%|raise %c, %c\n " , 0 , 1 )})
279281
280282 # exec as a built-in statement is only in Python 2.x
281283 def n_exec_stmt (node ):
0 commit comments