MCPcopy
hub / github.com/python/mypy / func_helper

Method func_helper

mypy/strconv.py:70–101  ·  view source on GitHub ↗

Return a list in a format suitable for dump() that represents the arguments and the body of a function. The caller can then decorate the array with information specific to methods, global functions or anonymous functions.

(self, o: mypy.nodes.FuncItem)

Source from the content-addressed store, hash-verified

68 return dump_tagged(nodes, tag, self)
69
70 def func_helper(self, o: mypy.nodes.FuncItem) -> list[object]:
71 """Return a list in a format suitable for dump() that represents the
72 arguments and the body of a function. The caller can then decorate the
73 array with information specific to methods, global functions or
74 anonymous functions.
75 """
76 args: list[mypy.nodes.Var | tuple[str, list[mypy.nodes.Node]]] = []
77 extra: list[tuple[str, list[mypy.nodes.Var]]] = []
78 for arg in o.arguments:
79 kind: mypy.nodes.ArgKind = arg.kind
80 if kind.is_required():
81 args.append(arg.variable)
82 elif kind.is_optional():
83 assert arg.initializer is not None
84 args.append(("default", [arg.variable, arg.initializer]))
85 elif kind == mypy.nodes.ARG_STAR:
86 extra.append(("VarArg", [arg.variable]))
87 elif kind == mypy.nodes.ARG_STAR2:
88 extra.append(("DictVarArg", [arg.variable]))
89 a: list[Any] = []
90 if o.type_args:
91 for p in o.type_args:
92 a.append(self.type_param(p))
93 if args:
94 a.append(("Args", args))
95 if o.type:
96 a.append(o.type)
97 if o.is_generator:
98 a.append("Generator")
99 a.extend(extra)
100 a.append(o.body)
101 return a
102
103 # Top-level structures
104

Callers 2

visit_func_defMethod · 0.95
visit_lambda_exprMethod · 0.95

Calls 5

type_paramMethod · 0.95
is_requiredMethod · 0.80
appendMethod · 0.80
extendMethod · 0.80
is_optionalMethod · 0.45

Tested by

no test coverage detected