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

Function customize_for_version

uncompyle6/semantics/customize.py:31–301  ·  view source on GitHub ↗
(self, is_pypy, version)

Source from the content-addressed store, hash-verified

29
30
31def customize_for_version(self, is_pypy, version):
32 if is_pypy:
33 ########################
34 # PyPy changes
35 #######################
36 # fmt: off
37 self.TABLE_DIRECT.update({
38
39 "assert": ("%|assert %c\n", 0),
40 # This can happen as a result of an if transformation
41 "assert2": ("%|assert %c, %c\n", 0, 3),
42 "assert_pypy": ( "%|assert %c\n" , (1, "assert_expr") ),
43 # This is as a result of an if transformation
44 'assert0_pypy': ( "%|assert %c\n" , 0),
45
46 'assert_not_pypy': ( "%|assert not %c\n" , (1, "assert_exp") ),
47 "assert2_not_pypy": (
48 "%|assert not %c, %c\n",
49 (1, "assert_exp"),
50 (4, "expr"),
51 ),
52
53 "try_except_pypy": ( "%|try:\n%+%c%-%c\n\n", 1, 2 ),
54 "tryfinallystmt_pypy": ( "%|try:\n%+%c%-%|finally:\n%+%c%-\n\n", 1, 3 ),
55 "assign3_pypy": ( "%|%c, %c, %c = %c, %c, %c\n", 5, 4, 3, 0, 1, 2 ),
56 "assign2_pypy": ( "%|%c, %c = %c, %c\n", 3, 2, 0, 1),
57 })
58 # fmt: on
59
60 if version[:2] >= (3, 7):
61
62 def n_call_kw_pypy37(node):
63 self.template_engine(("%p(", (0, NO_PARENTHESIS_EVER)), node)
64 assert node[-1] == "CALL_METHOD_KW"
65 arg_count = node[-1].attr
66 kw_names = node[-2]
67 assert kw_names == "pypy_kw_keys"
68
69 kwargs_names = kw_names[0].attr
70 kwarg_count = len(kwargs_names)
71 pos_argc = arg_count - kwarg_count
72
73 flat_elems = flatten_list(node[1:-2])
74 n = len(flat_elems)
75 assert n == arg_count, "n: %s, arg_count: %s\n%s" % (
76 n,
77 arg_count,
78 node,
79 )
80
81 sep = ""
82
83 for i in range(pos_argc):
84 elem = flat_elems[i]
85 line_number = self.line_number
86 value = self.traverse(elem)
87 if line_number != self.line_number:
88 sep += "\n" + self.indent + INDENT_PER_LEVEL[:-1]

Callers 1

__init__Method · 0.90

Calls 6

customize_for_version3Function · 0.90
customize_for_version25Function · 0.90
SyntaxTreeClass · 0.90
TokenClass · 0.90
customize_for_version14Function · 0.90

Tested by

no test coverage detected