|
542 | 542 | _PyST_IsFunctionLike(PySTEntryObject *ste)
|
543 | 543 | {
|
544 | 544 | return ste->ste_type == FunctionBlock
|
| 545 | + || ste->ste_type == AnnotationBlock |
545 | 546 | || ste->ste_type == TypeVarBoundBlock
|
546 | 547 | || ste->ste_type == TypeAliasBlock
|
547 | 548 | || ste->ste_type == TypeParamBlock;
|
@@ -2478,12 +2479,20 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation,
|
2478 | 2479 | }
|
2479 | 2480 | else {
|
2480 | 2481 | if (st->st_cur->ste_annotation_block == NULL) {
|
| 2482 | + _Py_block_ty current_type = st->st_cur->ste_type; |
2481 | 2483 | if (!symtable_enter_block(st, parent_ste->ste_name, AnnotationBlock,
|
2482 | 2484 | key, LOCATION(annotation))) {
|
2483 | 2485 | VISIT_QUIT(st, 0);
|
2484 | 2486 | }
|
2485 | 2487 | parent_ste->ste_annotation_block =
|
2486 | 2488 | (struct _symtable_entry *)Py_NewRef(st->st_cur);
|
| 2489 | + if (current_type == ClassBlock) { |
| 2490 | + st->st_cur->ste_can_see_class_scope = 1; |
| 2491 | + if (!symtable_add_def(st, &_Py_ID(__classdict__), USE, LOCATION(annotation))) { |
| 2492 | + return 0; |
| 2493 | + } |
| 2494 | + } |
| 2495 | + |
2487 | 2496 | _Py_DECLARE_STR(format, ".format");
|
2488 | 2497 | // We need to insert code that reads this "parameter" to the function.
|
2489 | 2498 | if (!symtable_add_def(st, &_Py_STR(format), DEF_PARAM,
|
@@ -2531,10 +2540,17 @@ static int
|
2531 | 2540 | symtable_visit_annotations(struct symtable *st, stmt_ty o, arguments_ty a, expr_ty returns,
|
2532 | 2541 | struct _symtable_entry *function_ste)
|
2533 | 2542 | {
|
| 2543 | + _Py_block_ty current_type = st->st_cur->ste_type; |
2534 | 2544 | if (!symtable_enter_block(st, function_ste->ste_name, AnnotationBlock,
|
2535 | 2545 | (void *)a, LOCATION(o))) {
|
2536 | 2546 | VISIT_QUIT(st, 0);
|
2537 | 2547 | }
|
| 2548 | + if (current_type == ClassBlock) { |
| 2549 | + st->st_cur->ste_can_see_class_scope = 1; |
| 2550 | + if (!symtable_add_def(st, &_Py_ID(__classdict__), USE, LOCATION(o))) { |
| 2551 | + return 0; |
| 2552 | + } |
| 2553 | + } |
2538 | 2554 | _Py_DECLARE_STR(format, ".format");
|
2539 | 2555 | // We need to insert code that reads this "parameter" to the function.
|
2540 | 2556 | if (!symtable_add_def(st, &_Py_STR(format), DEF_PARAM, LOCATION(o))) {
|
@@ -2793,7 +2809,7 @@ symtable_visit_dictcomp(struct symtable *st, expr_ty e)
|
2793 | 2809 | static int
|
2794 | 2810 | symtable_raise_if_annotation_block(struct symtable *st, const char *name, expr_ty e)
|
2795 | 2811 | {
|
2796 |
| - enum _block_type type = st->st_cur->ste_type; |
| 2812 | + _Py_block_ty type = st->st_cur->ste_type; |
2797 | 2813 | if (type == AnnotationBlock)
|
2798 | 2814 | PyErr_Format(PyExc_SyntaxError, ANNOTATION_NOT_ALLOWED, name);
|
2799 | 2815 | else if (type == TypeVarBoundBlock)
|
|
0 commit comments