MCPcopy Index your code
hub / github.com/rocky/python-uncompyle6 / customize_for_version3

Function customize_for_version3

uncompyle6/semantics/customize3.py:32–372  ·  view source on GitHub ↗
(self, version: tuple)

Source from the content-addressed store, hash-verified

30
31
32def customize_for_version3(self, version: tuple):
33 self.TABLE_DIRECT.update(
34 {
35 "comp_for": (" for %c in %c", (2, "store"), (0, "expr")),
36 "if_exp_not": (
37 "%c if not %c else %c",
38 (2, "expr"),
39 (0, "expr"),
40 (4, "expr"),
41 ),
42 "except_cond2": ("%|except %c as %c:\n", (1, "expr"), (5, "store")),
43 "function_def_annotate": ("\n\n%|def %c%c\n", -1, 0),
44 # When a generator is a single parameter of a function,
45 # it doesn't need the surrounding parenethesis.
46 "call_generator": ("%c%P", 0, (1, -1, ", ", 100)),
47 "importmultiple": ("%|import %c%c\n", 2, 3),
48 "import_cont": (", %c", 2),
49 "kwarg": ("%[0]{attr}=%c", 1),
50 "raise_stmt2": ("%|raise %c from %c\n", 0, 1),
51 "tf_tryelsestmtl3": ("%c%-%c%|else:\n%+%c", 1, 3, 5),
52 "store_locals": ("%|# inspect.currentframe().f_locals = __locals__\n",),
53 "with": ("%|with %c:\n%+%c%-", 0, 3),
54 }
55 )
56
57 assert version >= (3, 0)
58
59 # In 2.5+ and 3.0+ "except" handlers and the "finally" can appear in one
60 # "try" statement. So the below has the effect of combining the
61 # "tryfinally" with statement with the "try_except" statement.
62 # FIXME: something doesn't smell right, since the semantics
63 # are different. See test_fileio.py for an example that shows this.
64 def tryfinallystmt(node):
65 suite_stmts = node[1][0]
66 if len(suite_stmts) == 1 and suite_stmts[0] == "stmt":
67 stmt = suite_stmts[0]
68 try_something = stmt[0]
69 if try_something == "try_except":
70 try_something.kind = "tf_try_except"
71 if try_something.kind.startswith("tryelsestmt"):
72 if try_something == "tryelsestmtl3":
73 try_something.kind = "tf_tryelsestmtl3"
74 else:
75 try_something.kind = "tf_tryelsestmt"
76 self.default(node)
77
78 self.n_tryfinallystmt = tryfinallystmt
79
80 def n_classdef3(node):
81 """Handle "classdef" nonterminal for 3.0 >= version 3.0 < 3.6"""
82
83 assert (3, 0) <= self.version < (3, 6)
84
85 # class definition ('class X(A,B,C):')
86 cclass = self.currentclass
87
88 # Pick out various needed bits of information
89 # * class_name - the name of the class

Callers 1

customize_for_versionFunction · 0.90

Calls 4

customize_for_version35Function · 0.90
customize_for_version36Function · 0.90
customize_for_version37Function · 0.90
customize_for_version38Function · 0.90

Tested by

no test coverage detected