(func: FunctionType, indent: int)
| 155 | |
| 156 | |
| 157 | def arguments(func: FunctionType, indent: int) -> str: |
| 158 | hints = get_type_hints(func, globals()) |
| 159 | tokens = [] |
| 160 | split = ",\n" + " " * indent |
| 161 | for [name, value] in hints.items(): |
| 162 | value_str = str(value) |
| 163 | if name == "return": |
| 164 | continue |
| 165 | assert ( |
| 166 | "_" not in name |
| 167 | ), f"Underscore in impl classes is not allowed, use camel case, func={func}, name={name}" |
| 168 | if "Callable" in value_str: |
| 169 | tokens.append(f"{name}=self._wrap_handler({to_snake_case(name)})") |
| 170 | elif name == "timeout" and "float" in value_str: |
| 171 | tokens.append(f"{name}=to_milliseconds({to_snake_case(name)})") |
| 172 | elif ( |
| 173 | "typing.Any" in value_str |
| 174 | or "typing.Dict" in value_str |
| 175 | or "typing.Sequence" in value_str |
| 176 | or "Handle" in value_str |
| 177 | ): |
| 178 | tokens.append(f"{name}=mapping.to_impl({to_snake_case(name)})") |
| 179 | elif ( |
| 180 | re.match(r"<class 'playwright\._impl\.[\w]+\.[\w]+", value_str) |
| 181 | and "_api_structures" not in value_str |
| 182 | ): |
| 183 | tokens.append(f"{name}={to_snake_case(name)}._impl_obj") |
| 184 | elif ( |
| 185 | re.match(r"typing\.Optional\[playwright\._impl\.[\w]+\.[\w]+\]", value_str) |
| 186 | and "_api_structures" not in value_str |
| 187 | ): |
| 188 | tokens.append( |
| 189 | f"{name}={to_snake_case(name)}._impl_obj if {to_snake_case(name)} else None" |
| 190 | ) |
| 191 | else: |
| 192 | tokens.append(f"{name}={to_snake_case(name)}") |
| 193 | return split.join(tokens) |
| 194 | |
| 195 | |
| 196 | def return_type(func: FunctionType) -> str: |
no test coverage detected