MCPcopy
hub / github.com/rocky/python-uncompyle6 / closure_walk

Method closure_walk

uncompyle6/semantics/fragments.py:982–1033  ·  view source on GitHub ↗

Set comprehensions the way they are done in Python3. They're more other comprehensions, e.g. set comprehensions See if we can combine code.

(self, node, collection_index)

Source from the content-addressed store, hash-verified

980 self.set_pos_info(node[1], node[0][0].start, node[0][0].finish)
981
982 def closure_walk(self, node, collection_index):
983 """Set comprehensions the way they are done in Python3.
984 They're more other comprehensions, e.g. set comprehensions
985 See if we can combine code.
986 """
987 p = self.prec
988 self.prec = 27
989
990 code = Code(node[1].attr, self.scanner, self.currentclass)
991 ast = self.build_ast(code._tokens, code._customize, code)
992 self.customize(code._customize)
993 ast = ast[0][0][0]
994 store = ast[3]
995 collection = node[collection_index]
996
997 n = ast[4]
998 list_if = None
999 assert n == "comp_iter"
1000
1001 # find inner-most node
1002 while n == "comp_iter":
1003 n = n[0] # recurse one step
1004 # FIXME: adjust for set comprehension
1005 if n == "list_for":
1006 store = n[2]
1007 n = n[3]
1008 elif n in ("list_if", "list_if_not", "comp_if", "comp_if_not"):
1009 # FIXME: just a guess
1010 if n[0].kind == "expr":
1011 list_if = n
1012 else:
1013 list_if = n[1]
1014 n = n[2]
1015 pass
1016 pass
1017
1018 assert n == "comp_body", ast
1019
1020 self.preorder(n[0])
1021 self.write(" for ")
1022 start = len(self.f.getvalue())
1023 self.preorder(store)
1024 self.set_pos_info(store, start, len(self.f.getvalue()))
1025 self.write(" in ")
1026 start = len(self.f.getvalue())
1027 self.preorder(collection)
1028 self.set_pos_info(collection, start, len(self.f.getvalue()))
1029 if list_if:
1030 start = len(self.f.getvalue())
1031 self.preorder(list_if)
1032 self.set_pos_info(list_if, start, len(self.f.getvalue()))
1033 self.prec = p
1034
1035 def n_classdef(self, node):
1036 # class definition ('class X(A,B,C):')

Callers 3

n_set_compMethod · 0.95
n_generator_expMethod · 0.45
n_set_compMethod · 0.45

Calls 6

build_astMethod · 0.95
preorderMethod · 0.95
set_pos_infoMethod · 0.95
CodeClass · 0.90
customizeMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected