@@ -270,6 +270,23 @@ make_typevar_with_constraints(PyThreadState* Py_UNUSED(ignored), PyObject *name,
270270 return _Py_make_typevar (name , NULL , evaluate_constraints );
271271}
272272
273+ static PyObject *
274+ add_conditional_annotation (PyThreadState * tstate , PyObject * conditional_annotations ,
275+ PyObject * index )
276+ {
277+ // gh-154902: user code can rebind __conditional_annotations__ to any object
278+ if (!PySet_Check (conditional_annotations )) {
279+ _PyErr_Format (tstate , PyExc_TypeError ,
280+ "__conditional_annotations__ must be a set, not %T" ,
281+ conditional_annotations );
282+ return NULL ;
283+ }
284+ if (PySet_Add (conditional_annotations , index ) < 0 ) {
285+ return NULL ;
286+ }
287+ Py_RETURN_NONE ;
288+ }
289+
273290const intrinsic_func2_info
274291_PyIntrinsics_BinaryFunctions [] = {
275292 INTRINSIC_FUNC_ENTRY (INTRINSIC_2_INVALID , no_intrinsic2 )
@@ -278,6 +295,7 @@ _PyIntrinsics_BinaryFunctions[] = {
278295 INTRINSIC_FUNC_ENTRY (INTRINSIC_TYPEVAR_WITH_CONSTRAINTS , make_typevar_with_constraints )
279296 INTRINSIC_FUNC_ENTRY (INTRINSIC_SET_FUNCTION_TYPE_PARAMS , _Py_set_function_type_params )
280297 INTRINSIC_FUNC_ENTRY (INTRINSIC_SET_TYPEPARAM_DEFAULT , _Py_set_typeparam_default )
298+ INTRINSIC_FUNC_ENTRY (INTRINSIC_ADD_CONDITIONAL_ANNOTATION , add_conditional_annotation )
281299};
282300
283301#undef INTRINSIC_FUNC_ENTRY
0 commit comments