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

Method custom_classfunc_rule

uncompyle6/parsers/parse37.py:1578–1702  ·  view source on GitHub ↗
(self, opname, token, customize, next_token)

Source from the content-addressed store, hash-verified

1576 pass
1577
1578 def custom_classfunc_rule(self, opname, token, customize, next_token):
1579 args_pos, args_kw = self.get_pos_kw(token)
1580
1581 # Additional exprs for * and ** args:
1582 # 0 if neither
1583 # 1 for CALL_FUNCTION_VAR or CALL_FUNCTION_KW
1584 # 2 for * and ** args (CALL_FUNCTION_VAR_KW).
1585 # Yes, this computation based on instruction name is a little bit hoaky.
1586 nak = (len(opname) - len("CALL_FUNCTION")) // 3
1587 uniq_param = args_kw + args_pos
1588
1589 if frozenset(("GET_AWAITABLE", "YIELD_FROM")).issubset(self.seen_ops):
1590 rule = (
1591 """
1592 await ::= GET_AWAITABLE LOAD_CONST YIELD_FROM
1593 await_expr ::= expr await
1594 expr ::= await_expr
1595 async_call ::= expr """
1596 + ("pos_arg " * args_pos)
1597 + ("kwarg " * args_kw)
1598 + "expr " * nak
1599 + token.kind
1600 + " GET_AWAITABLE LOAD_CONST YIELD_FROM"
1601 )
1602 self.add_unique_doc_rules(rule, customize)
1603 self.add_unique_rule(
1604 "expr ::= async_call", token.kind, uniq_param, customize
1605 )
1606
1607 if opname.startswith("CALL_FUNCTION_KW"):
1608 self.addRule("expr ::= call_kw36", nop_func)
1609 values = "expr " * token.attr
1610 rule = "call_kw36 ::= expr {values} LOAD_CONST {opname}".format(**locals())
1611 self.add_unique_rule(rule, token.kind, token.attr, customize)
1612 elif opname == "CALL_FUNCTION_EX_KW":
1613 # Note: this doesn't exist in 3.7 and later
1614 self.addRule(
1615 """expr ::= call_ex_kw4
1616 call_ex_kw4 ::= expr
1617 expr
1618 expr
1619 CALL_FUNCTION_EX_KW
1620 """,
1621 nop_func,
1622 )
1623 if "BUILD_MAP_UNPACK_WITH_CALL" in self.seen_op_basenames:
1624 self.addRule(
1625 """expr ::= call_ex_kw
1626 call_ex_kw ::= expr expr build_map_unpack_with_call
1627 CALL_FUNCTION_EX_KW
1628 """,
1629 nop_func,
1630 )
1631 if "BUILD_TUPLE_UNPACK_WITH_CALL" in self.seen_op_basenames:
1632 # FIXME: should this be parameterized by EX value?
1633 self.addRule(
1634 """expr ::= call_ex_kw3
1635 call_ex_kw3 ::= expr

Callers

nothing calls this directly

Calls 4

get_pos_kwMethod · 0.80
add_unique_doc_rulesMethod · 0.80
add_unique_ruleMethod · 0.80
formatMethod · 0.80

Tested by

no test coverage detected