1- # Copyright (c) 2015-2019, 2021-2024 by Rocky Bernstein
1+ # Copyright (c) 2015-2019, 2021-2025 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
7373from xdis import iscode
7474from xdis .version_info import IS_PYPY , PYTHON_VERSION_TRIPLE
7575
76- import uncompyle6 .parser as python_parser
76+ from uncompyle6 .parser import ParserError as ParserError , parse
7777from uncompyle6 .parsers .treenode import SyntaxTree
7878from uncompyle6 .scanner import Code , Token , get_scanner
79- from uncompyle6 .semantics import pysource
8079from uncompyle6 .semantics .check_ast import checker
8180from uncompyle6 .semantics .consts import (
8281 INDENT_PER_LEVEL ,
9089from uncompyle6 .semantics .pysource import (
9190 DEFAULT_DEBUG_OPTS ,
9291 TREE_DEFAULT_DEBUG ,
93- ParserError ,
92+ SourceWalker ,
9493 StringIO ,
94+ find_globals_and_nonlocals ,
9595)
9696from uncompyle6 .show import maybe_show_asm , maybe_show_tree
9797
147147}
148148
149149
150- class FragmentsWalker (pysource . SourceWalker , object ):
150+ class FragmentsWalker (SourceWalker , object ):
151151 MAP_DIRECT_FRAGMENT = ()
152152
153153 stacked_params = ("f" , "indent" , "is_lambda" , "_globals" )
@@ -163,7 +163,7 @@ def __init__(
163163 linestarts = {},
164164 tolerate_errors = True ,
165165 ):
166- pysource . SourceWalker .__init__ (
166+ SourceWalker .__init__ (
167167 self ,
168168 version = version ,
169169 out = StringIO (),
@@ -237,7 +237,7 @@ def set_pos_info(self, node, start, finish, name=None):
237237
238238 def preorder (self , node = None ):
239239 start = len (self .f .getvalue ())
240- super (pysource . SourceWalker , self ).preorder (node )
240+ super (SourceWalker , self ).preorder (node )
241241 self .set_pos_info (node , start , len (self .f .getvalue ()))
242242
243243 return
@@ -1177,11 +1177,11 @@ def build_ast(
11771177 p_insts = self .p .insts
11781178 self .p .insts = self .scanner .insts
11791179 self .p .offset2inst_index = self .scanner .offset2inst_index
1180- ast = python_parser . parse (self .p , tokens , customize , code )
1180+ ast = parse (self .p , tokens , customize , code )
11811181 self .customize (customize )
11821182 self .p .insts = p_insts
11831183
1184- except (python_parser . ParserError , AssertionError ) as e :
1184+ except (ParserError , AssertionError ) as e :
11851185 raise ParserError (e , tokens )
11861186 transform_tree = self .treeTransform .transform (ast , code )
11871187 maybe_show_tree (self , ast )
@@ -1219,9 +1219,9 @@ def build_ast(
12191219 self .p .insts = self .scanner .insts
12201220 self .p .offset2inst_index = self .scanner .offset2inst_index
12211221 self .p .opc = self .scanner .opc
1222- ast = python_parser . parse (self .p , tokens , customize , code )
1222+ ast = parse (self .p , tokens , customize , code )
12231223 self .p .insts = p_insts
1224- except (python_parser . ParserError , AssertionError ) as e :
1224+ except (ParserError , AssertionError ) as e :
12251225 raise ParserError (e , tokens , {})
12261226
12271227 checker (ast , False , self .ast_errors )
@@ -2116,7 +2116,7 @@ def code_deparse(
21162116 debug_parser ["errorstack" ] = True
21172117
21182118 # Build Syntax Tree from tokenized and massaged disassembly.
2119- # deparsed = pysource. FragmentsWalker(out, scanner, showast=showast)
2119+ # deparsed = FragmentsWalker(out, scanner, showast=showast)
21202120 show_tree = debug_opts .get ("tree" , False )
21212121 linestarts = dict (scanner .opc .findlinestarts (co ))
21222122 deparsed = walker (
@@ -2142,7 +2142,7 @@ def code_deparse(
21422142 # convert leading '__doc__ = "..." into doc string
21432143 assert deparsed .ast == "stmts"
21442144
2145- (deparsed .mod_globs , _ ) = pysource . find_globals_and_nonlocals (
2145+ (deparsed .mod_globs , _ ) = find_globals_and_nonlocals (
21462146 deparsed .ast , set (), set (), co , version
21472147 )
21482148
0 commit comments