Indeed, this issue is more complex than it looked to me.
Technically, LOAD_FAST, which is used for reading the loop
control variables in comprehensions, uses the array f->f_localsplus, while LOAD_NAME uses f->f_locals and f->f_globals. When executing class bodies, f->f_localsplus is NULL, and if executing functions f->f_locals usually is a NULL or a cached copy of a dict created from f->f_localsplus. But we can create a hybrid frame for comprehensions in class body, which will contain independent f->f_localsplus and f->f_locals. References to the loop
control variables and to the class variables will work as expected, just the meaning of locals() will be changed.