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

Function make_generic_base_class

mypyc/irbuild/classdef.py:535–556  ·  view source on GitHub ↗

Construct Generic[...] base class object for a new-style generic class (Python 3.12).

(
    builder: IRBuilder, fullname: str, type_args: list[TypeParam], line: int
)

Source from the content-addressed store, hash-verified

533
534
535def 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

Callers 1

allocate_classFunction · 0.85

Calls 9

create_type_paramsFunction · 0.90
zipFunction · 0.85
lenFunction · 0.85
appendMethod · 0.80
call_cMethod · 0.45
load_strMethod · 0.45
primitive_opMethod · 0.45
py_get_attrMethod · 0.45
new_tupleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…