@@ -225,10 +225,17 @@ symtable_new(void)
225225struct symtable *
226226PySymtable_Build (mod_ty mod , const char * filename , PyFutureFeatures * future )
227227{
228- struct symtable * st = symtable_new () ;
228+ struct symtable * st ;
229229 asdl_seq * seq ;
230230 int i ;
231231
232+ if (__class__ == NULL ) {
233+ __class__ = PyUnicode_InternFromString ("@__class__" );
234+ if (__class__ == NULL )
235+ return NULL ;
236+ }
237+
238+ st = symtable_new ();
232239 if (st == NULL )
233240 return st ;
234241 st -> st_filename = filename ;
@@ -744,8 +751,6 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
744751 }
745752 else {
746753 /* Special-case __class__ */
747- if (!GET_IDENTIFIER (__class__ ))
748- goto error ;
749754 assert (PySet_Contains (local , __class__ ) == 1 );
750755 if (PySet_Add (newbound , __class__ ) < 0 )
751756 goto error ;
@@ -783,7 +788,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
783788 NULL ))
784789 goto error ;
785790 else if (ste -> ste_type == ClassBlock && !analyze_cells (scopes , newfree ,
786- "__class__" ))
791+ "@ __class__" ))
787792 goto error ;
788793 /* Records the results of the analysis in the symbol table entry */
789794 if (!update_symbols (ste -> ste_symbols , scopes , bound , newfree ,
@@ -1143,8 +1148,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
11431148 if (!symtable_enter_block (st , s -> v .ClassDef .name , ClassBlock ,
11441149 (void * )s , s -> lineno , s -> col_offset ))
11451150 return 0 ;
1146- if (!GET_IDENTIFIER (__class__ ) ||
1147- !symtable_add_def (st , __class__ , DEF_LOCAL ) ||
1151+ if (!symtable_add_def (st , __class__ , DEF_LOCAL ) ||
11481152 !GET_IDENTIFIER (__locals__ ) ||
11491153 !symtable_add_def (st , __locals__ , DEF_PARAM )) {
11501154 symtable_exit_block (st , s );
@@ -1417,8 +1421,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
14171421 if (e -> v .Name .ctx == Load &&
14181422 st -> st_cur -> ste_type == FunctionBlock &&
14191423 !PyUnicode_CompareWithASCIIString (e -> v .Name .id , "super" )) {
1420- if (!GET_IDENTIFIER (__class__ ) ||
1421- !symtable_add_def (st , __class__ , USE ))
1424+ if (!symtable_add_def (st , __class__ , USE ))
14221425 return 0 ;
14231426 }
14241427 break ;
0 commit comments