@@ -807,6 +807,8 @@ inline_comprehension(PySTEntryObject *ste, PySTEntryObject *comp,
807807 PyObject * k , * v ;
808808 Py_ssize_t pos = 0 ;
809809 int remove_dunder_class = 0 ;
810+ int remove_dunder_classdict = 0 ;
811+ int remove_dunder_cond_annotations = 0 ;
810812
811813 while (PyDict_Next (comp -> ste_symbols , & pos , & k , & v )) {
812814 // skip comprehension parameter
@@ -829,15 +831,27 @@ inline_comprehension(PySTEntryObject *ste, PySTEntryObject *comp,
829831 if (existing == NULL && PyErr_Occurred ()) {
830832 return 0 ;
831833 }
832- // __class__ is never allowed to be free through a class scope (see
834+ // __class__, __classdict__ and __conditional_annotations__ are
835+ // never allowed to be free through a class scope (see
833836 // drop_class_free)
834837 if (scope == FREE && ste -> ste_type == ClassBlock &&
835- _PyUnicode_EqualToASCIIString (k , "__class__" )) {
838+ (_PyUnicode_EqualToASCIIString (k , "__class__" ) ||
839+ _PyUnicode_EqualToASCIIString (k , "__classdict__" ) ||
840+ _PyUnicode_EqualToASCIIString (k , "__conditional_annotations__" ))) {
836841 scope = GLOBAL_IMPLICIT ;
837842 if (PySet_Discard (comp_free , k ) < 0 ) {
838843 return 0 ;
839844 }
840- remove_dunder_class = 1 ;
845+
846+ if (_PyUnicode_EqualToASCIIString (k , "__class__" )) {
847+ remove_dunder_class = 1 ;
848+ }
849+ else if (_PyUnicode_EqualToASCIIString (k , "__conditional_annotations__" )) {
850+ remove_dunder_cond_annotations = 1 ;
851+ }
852+ else {
853+ remove_dunder_classdict = 1 ;
854+ }
841855 }
842856 if (!existing ) {
843857 // name does not exist in scope, copy from comprehension
@@ -877,6 +891,12 @@ inline_comprehension(PySTEntryObject *ste, PySTEntryObject *comp,
877891 if (remove_dunder_class && PyDict_DelItemString (comp -> ste_symbols , "__class__" ) < 0 ) {
878892 return 0 ;
879893 }
894+ if (remove_dunder_classdict && PyDict_DelItemString (comp -> ste_symbols , "__classdict__" ) < 0 ) {
895+ return 0 ;
896+ }
897+ if (remove_dunder_cond_annotations && PyDict_DelItemString (comp -> ste_symbols , "__conditional_annotations__" ) < 0 ) {
898+ return 0 ;
899+ }
880900 return 1 ;
881901}
882902
0 commit comments