@@ -1462,6 +1462,9 @@ def _vectorcall_type_check(self) -> list[str]:
14621462 assert func .cls .type_object
14631463 return [libclinic .normalize_snippet (f"""
14641464 assert(Py_Is(_PyType_CAST(type), { func .cls .type_object } ));
1465+ # Make sure the type object is immutable: the generated
1466+ # vectorcall doesn't deal e.g. with users reassigning __init__
1467+ assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE));
14651468 """ , indent = 4 )]
14661469
14671470 def _vectorcall_positional (self , * ,
@@ -1483,9 +1486,7 @@ def _assemble_vectorcall(self, preamble: str, fields: tuple[str, ...],
14831486 """Wrap parser code in the vectorcall prototype."""
14841487 prototype = PARSER_PROTOTYPE_VECTORCALL .replace (
14851488 "{vc_basename}" , self .func .c_basename_vectorcall )
1486- lines = [prototype ]
1487- for field in preamble , * fields , finale :
1488- lines .append (field )
1489+ lines = [prototype , preamble , * fields , finale ]
14891490
14901491 if self .func .kind is METHOD_INIT :
14911492 markers = VECTORCALL_FINALE_MARKERS_INIT
@@ -1564,7 +1565,7 @@ def _vectorcall_delegate_to_helper(self, nkw: str) -> str:
15641565 markers = VECTORCALL_DELEGATE_MARKERS_INIT
15651566 else :
15661567 markers = VECTORCALL_DELEGATE_MARKERS_NEW
1567- markers = markers | { "helper_call" : markers ["helper_call" ] % { " nkw" : nkw }}
1568+ markers ["helper_call" ]. replace ( '$NKW' , nkw )
15681569 return libclinic .linear_format (VECTORCALL_DELEGATE_SKELETON , ** markers )
15691570
15701571 def parse_vectorcall_kw_required (self ) -> None :
0 commit comments