@@ -589,26 +589,28 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
589
589
}
590
590
return 1 ;
591
591
}
592
+ // If we were passed class_symbols (i.e., we're in an ste_can_see_class_scope scope)
593
+ // and the bound name is in that set, then the name is potentially bound both by
594
+ // the immediately enclosing class namespace, and also by an outer function namespace.
595
+ // In that case, we want the runtime name resolution to look at only the class
596
+ // namespace and the globals (not the namespace providing the bound).
597
+ // Similarly, if the name is explicitly global in the class namespace (through the
598
+ // global statement), we want to also treat it as a global in this scope.
599
+ long class_flags = flags_in_symbols (class_symbols , name );
600
+ if (class_flags & DEF_GLOBAL ) {
601
+ SET_SCOPE (scopes , name , GLOBAL_EXPLICIT );
602
+ return 1 ;
603
+ }
604
+ else if (class_flags & DEF_BOUND && !(class_flags & DEF_NONLOCAL )) {
605
+ SET_SCOPE (scopes , name , GLOBAL_IMPLICIT );
606
+ return 1 ;
607
+ }
592
608
/* If an enclosing block has a binding for this name, it
593
609
is a free variable rather than a global variable.
594
610
Note that having a non-NULL bound implies that the block
595
611
is nested.
596
612
*/
597
613
if (bound && PySet_Contains (bound , name )) {
598
- // If we were passed class_symbols (i.e., we're in an ste_can_see_class_scope scope)
599
- // and the bound name is in that set, then the name is potentially bound both by
600
- // the immediately enclosing class namespace, and also by an outer function namespace.
601
- // In that case, we want the runtime name resolution to look at only the class
602
- // namespace and the globals (not the namespace providing the bound).
603
- long class_flags = flags_in_symbols (class_symbols , name );
604
- if (class_flags & DEF_BOUND ) {
605
- SET_SCOPE (scopes , name , GLOBAL_IMPLICIT );
606
- return 1 ;
607
- }
608
- else if (class_flags & DEF_GLOBAL ) {
609
- SET_SCOPE (scopes , name , GLOBAL_EXPLICIT );
610
- return 1 ;
611
- }
612
614
SET_SCOPE (scopes , name , FREE );
613
615
ste -> ste_free = 1 ;
614
616
return PySet_Add (free , name ) >= 0 ;
0 commit comments