(
self,
f: Function,
template_dict: TemplateDict,
limited_capi: bool,
)
| 253 | return "group_" + adjective + str(abs(group)) |
| 254 | |
| 255 | def render_option_group_parsing( |
| 256 | self, |
| 257 | f: Function, |
| 258 | template_dict: TemplateDict, |
| 259 | limited_capi: bool, |
| 260 | ) -> None: |
| 261 | # positional only, grouped, optional arguments! |
| 262 | # can be optional on the left or right. |
| 263 | # here's an example: |
| 264 | # |
| 265 | # [ [ [ A1 A2 ] B1 B2 B3 ] C1 C2 ] D1 D2 D3 [ E1 E2 E3 [ F1 F2 F3 ] ] |
| 266 | # |
| 267 | # Here group D are required, and all other groups are optional. |
| 268 | # (Group D's "group" is actually None.) |
| 269 | # We can figure out which sets of arguments we have based on |
| 270 | # how many arguments are in the tuple. |
| 271 | # |
| 272 | # Note that you need to count up on both sides. For example, |
| 273 | # you could have groups C+D, or C+D+E, or C+D+E+F. |
| 274 | # |
| 275 | # What if the number of arguments leads us to an ambiguous result? |
| 276 | # Clinic prefers groups on the left. So in the above example, |
| 277 | # five arguments would map to B+C, not C+D. |
| 278 | |
| 279 | out = [] |
| 280 | parameters = list(f.parameters.values()) |
| 281 | if isinstance(parameters[0].converter, self_converter): |
| 282 | del parameters[0] |
| 283 | |
| 284 | group: list[Parameter] | None = None |
| 285 | left = [] |
| 286 | right = [] |
| 287 | required: list[Parameter] = [] |
| 288 | last: int | Literal[Sentinels.unspecified] = unspecified |
| 289 | |
| 290 | for p in parameters: |
| 291 | group_id = p.group |
| 292 | if group_id != last: |
| 293 | last = group_id |
| 294 | group = [] |
| 295 | if group_id < 0: |
| 296 | left.append(group) |
| 297 | elif group_id == 0: |
| 298 | group = required |
| 299 | else: |
| 300 | right.append(group) |
| 301 | assert group is not None |
| 302 | group.append(p) |
| 303 | |
| 304 | count_min = sys.maxsize |
| 305 | count_max = -1 |
| 306 | |
| 307 | if limited_capi: |
| 308 | nargs = 'PyTuple_Size(args)' |
| 309 | else: |
| 310 | nargs = 'PyTuple_GET_SIZE(args)' |
| 311 | out.append(f"switch ({nargs}) {{\n") |
| 312 | for subset in permute_optional_groups(left, required, right): |
no test coverage detected