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

Method n_ifstmt

uncompyle6/semantics/transform.py:144–271  ·  view source on GitHub ↗

Here we check if we can turn an `ifstmt` or 'iflaststmtl` into some kind of `assert` statement

(self, node)

Source from the content-addressed store, hash-verified

142 return node
143
144 def n_ifstmt(self, node):
145 """Here we check if we can turn an `ifstmt` or 'iflaststmtl` into
146 some kind of `assert` statement"""
147
148 testexpr = node[0]
149
150 if testexpr not in ("testexpr", "testexprl"):
151 return node
152
153 if node.kind in ("ifstmt", "ifstmtl"):
154 ifstmts_jump = node[1]
155
156 if ifstmts_jump == "_ifstmts_jumpl" and ifstmts_jump[0] == "_ifstmts_jump":
157 ifstmts_jump = ifstmts_jump[0]
158 elif ifstmts_jump not in (
159 "_ifstmts_jump",
160 "_ifstmts_jumpl",
161 "ifstmts_jumpl",
162 ):
163 return node
164 stmts = ifstmts_jump[0]
165 else:
166 # iflaststmtl works this way
167 stmts = node[1]
168
169 if stmts in ("c_stmts", "stmts", "stmts_opt") and len(stmts) == 1:
170 raise_stmt = stmts[0]
171 if raise_stmt != "raise_stmt1" and len(raise_stmt) > 0:
172 raise_stmt = raise_stmt[0]
173
174 testtrue_or_false = testexpr[0]
175 if (
176 raise_stmt.kind == "raise_stmt1"
177 and 1 <= len(testtrue_or_false) <= 2
178 and raise_stmt.first_child().pattr == "AssertionError"
179 ):
180 if testtrue_or_false in ("testtrue", "testtruel"):
181 # Skip over the testtrue because because it would
182 # produce a "not" and we don't want that here.
183 assert_expr = testtrue_or_false[0]
184 jump_cond = NoneToken
185 else:
186 assert testtrue_or_false in ("testfalse", "testfalsel")
187 assert_expr = testtrue_or_false[0]
188 if assert_expr in ("testfalse_not_and", "and_not"):
189 # FIXME: come back to stuff like this
190 return node
191
192 jump_cond = testtrue_or_false[1]
193 assert_expr.kind = "assert_expr"
194 pass
195
196 expr = raise_stmt[0]
197 RAISE_VARARGS_1 = raise_stmt[1]
198 call = expr[0]
199 if call == "call":
200 # ifstmt
201 # 0. testexpr

Callers

nothing calls this directly

Calls 2

SyntaxTreeClass · 0.90
first_childMethod · 0.80

Tested by

no test coverage detected