@@ -2569,11 +2569,21 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
25692569static int
25702570symtable_visit_type_param_bound_or_default (
25712571 struct symtable * st , expr_ty e , identifier name ,
2572- void * key , const char * ste_scope_info )
2572+ type_param_ty tp , const char * ste_scope_info )
25732573{
2574+ if (_PyUnicode_Equal (name , & _Py_ID (__classdict__ ))) {
2575+
2576+ PyObject * error_msg = PyUnicode_FromFormat ("reserved name '%U' cannot be "
2577+ "used for type parameter" , name );
2578+ PyErr_SetObject (PyExc_SyntaxError , error_msg );
2579+ Py_DECREF (error_msg );
2580+ SET_ERROR_LOCATION (st -> st_filename , LOCATION (tp ));
2581+ return 0 ;
2582+ }
2583+
25742584 if (e ) {
25752585 int is_in_class = st -> st_cur -> ste_can_see_class_scope ;
2576- if (!symtable_enter_block (st , name , TypeVariableBlock , key , LOCATION (e ))) {
2586+ if (!symtable_enter_block (st , name , TypeVariableBlock , ( void * ) tp , LOCATION (e ))) {
25772587 return 0 ;
25782588 }
25792589
@@ -2615,12 +2625,12 @@ symtable_visit_type_param(struct symtable *st, type_param_ty tp)
26152625 // The only requirement for the key is that it is unique and it matches the logic in
26162626 // compile.c where the scope is retrieved.
26172627 if (!symtable_visit_type_param_bound_or_default (st , tp -> v .TypeVar .bound , tp -> v .TypeVar .name ,
2618- ( void * ) tp , ste_scope_info )) {
2628+ tp , ste_scope_info )) {
26192629 return 0 ;
26202630 }
26212631
26222632 if (!symtable_visit_type_param_bound_or_default (st , tp -> v .TypeVar .default_value , tp -> v .TypeVar .name ,
2623- (void * )((uintptr_t )tp + 1 ), "a TypeVar default" )) {
2633+ (type_param_ty )((uintptr_t )tp + 1 ), "a TypeVar default" )) {
26242634 return 0 ;
26252635 }
26262636 break ;
@@ -2630,7 +2640,7 @@ symtable_visit_type_param(struct symtable *st, type_param_ty tp)
26302640 }
26312641
26322642 if (!symtable_visit_type_param_bound_or_default (st , tp -> v .TypeVarTuple .default_value , tp -> v .TypeVarTuple .name ,
2633- ( void * ) tp , "a TypeVarTuple default" )) {
2643+ tp , "a TypeVarTuple default" )) {
26342644 return 0 ;
26352645 }
26362646 break ;
@@ -2640,7 +2650,7 @@ symtable_visit_type_param(struct symtable *st, type_param_ty tp)
26402650 }
26412651
26422652 if (!symtable_visit_type_param_bound_or_default (st , tp -> v .ParamSpec .default_value , tp -> v .ParamSpec .name ,
2643- ( void * ) tp , "a ParamSpec default" )) {
2653+ tp , "a ParamSpec default" )) {
26442654 return 0 ;
26452655 }
26462656 break ;
0 commit comments