MCPcopy Index your code
hub / github.com/python/mypy / calculate_arg_defaults

Function calculate_arg_defaults

mypyc/irbuild/builder.py:1715–1739  ·  view source on GitHub ↗

Calculate default argument values and store them. They are stored in statics for top level functions and in the function objects for nested functions (while constants are still stored computed on demand).

(
    builder: IRBuilder,
    fn_info: FuncInfo,
    func_reg: Value | None,
    symtable: dict[SymbolNode, SymbolTarget],
)

Source from the content-addressed store, hash-verified

1713
1714
1715def calculate_arg_defaults(
1716 builder: IRBuilder,
1717 fn_info: FuncInfo,
1718 func_reg: Value | None,
1719 symtable: dict[SymbolNode, SymbolTarget],
1720) -> None:
1721 """Calculate default argument values and store them.
1722
1723 They are stored in statics for top level functions and in
1724 the function objects for nested functions (while constants are
1725 still stored computed on demand).
1726 """
1727 fitem = fn_info.fitem
1728 for arg in fitem.arguments:
1729 # Constant values don't get stored but just recomputed
1730 if arg.initializer and not is_constant(arg.initializer):
1731 value = builder.coerce(
1732 builder.accept(arg.initializer), symtable[arg.variable].type, arg.line
1733 )
1734 if not fn_info.is_nested:
1735 name = fitem.fullname + "." + arg.variable.name
1736 builder.add(InitStatic(value, name, builder.module_name))
1737 else:
1738 assert func_reg is not None
1739 builder.add(SetAttr(func_reg, arg.variable.name, value, arg.line))

Callers 2

gen_func_bodyFunction · 0.90
gen_generator_func_bodyFunction · 0.90

Calls 6

is_constantFunction · 0.90
InitStaticClass · 0.90
SetAttrClass · 0.90
coerceMethod · 0.45
acceptMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…