Construct Generic[...] base class object for a new-style generic class (Python 3.12).
(
builder: IRBuilder, fullname: str, type_args: list[TypeParam], line: int
)
| 533 | |
| 534 | |
| 535 | def make_generic_base_class( |
| 536 | builder: IRBuilder, fullname: str, type_args: list[TypeParam], line: int |
| 537 | ) -> Value: |
| 538 | """Construct Generic[...] base class object for a new-style generic class (Python 3.12).""" |
| 539 | mod = builder.call_c(import_op, [builder.load_str("_typing")], line) |
| 540 | tvs = create_type_params(builder, mod, type_args, line) |
| 541 | args = [] |
| 542 | for tv, type_param in zip(tvs, type_args): |
| 543 | if type_param.kind == TYPE_VAR_TUPLE_KIND: |
| 544 | # Evaluate *Ts for a TypeVarTuple |
| 545 | it = builder.primitive_op(iter_op, [tv], line) |
| 546 | tv = builder.call_c(next_op, [it], line) |
| 547 | args.append(tv) |
| 548 | |
| 549 | gent = builder.py_get_attr(mod, "Generic", line) |
| 550 | if len(args) == 1: |
| 551 | arg = args[0] |
| 552 | else: |
| 553 | arg = builder.new_tuple(args, line) |
| 554 | |
| 555 | base = builder.primitive_op(py_get_item_op, [gent, arg], line) |
| 556 | return base |
| 557 | |
| 558 | |
| 559 | # Mypy uses these internally as base classes of TypedDict classes. These are |
no test coverage detected
searching dependent graphs…