@@ -2292,12 +2292,27 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
22922292static int
22932293symtable_visit_type_param_bound_or_default (
22942294 struct symtable * st , expr_ty e , identifier name ,
2295- void * key , const char * ste_scope_info )
2295+ type_param_ty tp , const char * ste_scope_info )
22962296{
2297+ if (_PyUnicode_Equal (name , & _Py_ID (__classdict__ ))) {
2298+
2299+ PyObject * error_msg = PyUnicode_FromFormat ("reserved name '%U' cannot be "
2300+ "used for type parameter" , name );
2301+ PyErr_SetObject (PyExc_SyntaxError , error_msg );
2302+ Py_DECREF (error_msg );
2303+ PyErr_RangedSyntaxLocationObject (st -> st_filename ,
2304+ tp -> lineno ,
2305+ tp -> col_offset + 1 ,
2306+ tp -> end_lineno ,
2307+ tp -> end_col_offset + 1 );
2308+ return 0 ;
2309+ }
2310+
22972311 if (e ) {
22982312 int is_in_class = st -> st_cur -> ste_can_see_class_scope ;
2299- if (!symtable_enter_block (st , name , TypeVariableBlock , key , LOCATION (e )))
2313+ if (!symtable_enter_block (st , name , TypeVariableBlock , ( void * ) tp , LOCATION (e ))) {
23002314 return 0 ;
2315+ }
23012316
23022317 st -> st_cur -> ste_can_see_class_scope = is_in_class ;
23032318 if (is_in_class && !symtable_add_def (st , & _Py_ID (__classdict__ ), USE , LOCATION (e ))) {
@@ -2341,12 +2356,12 @@ symtable_visit_type_param(struct symtable *st, type_param_ty tp)
23412356 // The only requirement for the key is that it is unique and it matches the logic in
23422357 // compile.c where the scope is retrieved.
23432358 if (!symtable_visit_type_param_bound_or_default (st , tp -> v .TypeVar .bound , tp -> v .TypeVar .name ,
2344- ( void * ) tp , ste_scope_info )) {
2359+ tp , ste_scope_info )) {
23452360 VISIT_QUIT (st , 0 );
23462361 }
23472362
23482363 if (!symtable_visit_type_param_bound_or_default (st , tp -> v .TypeVar .default_value , tp -> v .TypeVar .name ,
2349- (void * )((uintptr_t )tp + 1 ), "a TypeVar default" )) {
2364+ (type_param_ty )((uintptr_t )tp + 1 ), "a TypeVar default" )) {
23502365 VISIT_QUIT (st , 0 );
23512366 }
23522367 break ;
@@ -2356,7 +2371,7 @@ symtable_visit_type_param(struct symtable *st, type_param_ty tp)
23562371 }
23572372
23582373 if (!symtable_visit_type_param_bound_or_default (st , tp -> v .TypeVarTuple .default_value , tp -> v .TypeVarTuple .name ,
2359- ( void * ) tp , "a TypeVarTuple default" )) {
2374+ tp , "a TypeVarTuple default" )) {
23602375 VISIT_QUIT (st , 0 );
23612376 }
23622377 break ;
@@ -2366,7 +2381,7 @@ symtable_visit_type_param(struct symtable *st, type_param_ty tp)
23662381 }
23672382
23682383 if (!symtable_visit_type_param_bound_or_default (st , tp -> v .ParamSpec .default_value , tp -> v .ParamSpec .name ,
2369- ( void * ) tp , "a ParamSpec default" )) {
2384+ tp , "a ParamSpec default" )) {
23702385 VISIT_QUIT (st , 0 );
23712386 }
23722387 break ;
0 commit comments