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

Function make_format_string

mypyc/codegen/emitwrapper.py:104–131  ·  view source on GitHub ↗

Return a format string that specifies the accepted arguments. The format string is an extended subset of what is supported by PyArg_ParseTupleAndKeywords(). Only the type 'O' is used, and we also support some extensions: - Required keyword-only arguments are introduced after '@'

(func_name: str | None, groups: dict[ArgKind, list[RuntimeArg]])

Source from the content-addressed store, hash-verified

102
103
104def make_format_string(func_name: str | None, groups: dict[ArgKind, list[RuntimeArg]]) -> str:
105 """Return a format string that specifies the accepted arguments.
106
107 The format string is an extended subset of what is supported by
108 PyArg_ParseTupleAndKeywords(). Only the type 'O' is used, and we
109 also support some extensions:
110
111 - Required keyword-only arguments are introduced after '@'
112 - If the function receives *args or **kwargs, we add a '%' prefix
113
114 Each group requires the previous groups' delimiters to be present
115 first.
116
117 These are used by both vectorcall and legacy wrapper functions.
118 """
119 format = ""
120 if groups[ARG_STAR] or groups[ARG_STAR2]:
121 format += "%"
122 format += "O" * len(groups[ARG_POS])
123 if groups[ARG_OPT] or groups[ARG_NAMED_OPT] or groups[ARG_NAMED]:
124 format += "|" + "O" * len(groups[ARG_OPT])
125 if groups[ARG_NAMED_OPT] or groups[ARG_NAMED]:
126 format += "$" + "O" * len(groups[ARG_NAMED_OPT])
127 if groups[ARG_NAMED]:
128 format += "@" + "O" * len(groups[ARG_NAMED])
129 if func_name is not None:
130 format += f":{func_name}"
131 return format
132
133
134def generate_wrapper_function(

Callers 2

Calls 1

lenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…