MCPcopy Index your code
hub / github.com/microsoft/playwright-python / signature

Function signature

scripts/generate_api.py:124–154  ·  view source on GitHub ↗
(func: FunctionType, indent: int)

Source from the content-addressed store, hash-verified

122
123
124def signature(func: FunctionType, indent: int) -> str:
125 hints = get_type_hints(func, globals())
126 tokens = ["self"]
127 split = ",\n" + " " * indent
128
129 saw_optional = False
130 for [name, value] in hints.items():
131 if name == "return":
132 continue
133 positional_exception = is_positional_exception(f"{func.__name__}.{name}")
134 if saw_optional and positional_exception:
135 raise Exception(
136 "Positional exception is not first in the list "
137 + f"{func.__name__}.{name}"
138 )
139 processed = process_type(value, True)
140 if name == "timeout":
141 processed = re.sub(
142 r"\bfloat\b",
143 "typing.Union[float, datetime.timedelta]",
144 processed,
145 )
146 if (
147 not positional_exception
148 and not saw_optional
149 and processed.startswith("typing.Optional")
150 ):
151 saw_optional = True
152 tokens.append("*")
153 tokens.append(f"{to_snake_case(name)}: {processed}")
154 return split.join(tokens)
155
156
157def arguments(func: FunctionType, indent: int) -> str:

Callers 2

generateFunction · 0.90
generateFunction · 0.90

Calls 6

to_snake_caseFunction · 0.90
get_type_hintsFunction · 0.85
is_positional_exceptionFunction · 0.85
process_typeFunction · 0.85
appendMethod · 0.80
itemsMethod · 0.45

Tested by

no test coverage detected