|
91 | 91 |
|
92 | 92 | #define IS_ASYNC_DEF(st) ((st)->st_cur->ste_type == FunctionBlock && (st)->st_cur->ste_coroutine) |
93 | 93 |
|
| 94 | +static int |
| 95 | +ste_uses_fast_locals(PySTEntryObject *ste) |
| 96 | +{ |
| 97 | + return _PyST_IsFunctionLike(ste) || ste->ste_type == InlinedComprehensionBlock; |
| 98 | +} |
| 99 | + |
94 | 100 | static PySTEntryObject * |
95 | 101 | ste_new(struct symtable *st, identifier name, _Py_block_ty block, |
96 | 102 | void *key, _Py_SourceLocation loc) |
@@ -130,8 +136,7 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block, |
130 | 136 |
|
131 | 137 | if (st->st_cur != NULL && |
132 | 138 | (st->st_cur->ste_nested || |
133 | | - _PyST_IsFunctionLike(st->st_cur) || |
134 | | - st->st_cur->ste_type == InlinedComprehensionBlock)) |
| 139 | + ste_uses_fast_locals(st->st_cur))) |
135 | 140 | ste->ste_nested = 1; |
136 | 141 | ste->ste_generator = 0; |
137 | 142 | ste->ste_coroutine = 0; |
@@ -582,13 +587,6 @@ _PyST_IsFunctionLike(PySTEntryObject *ste) |
582 | 587 | || ste->ste_type == TypeParametersBlock; |
583 | 588 | } |
584 | 589 |
|
585 | | -/* True if this block binds locals that are visible to nested scopes */ |
586 | | -static int |
587 | | -ste_binds_locals_for_children(PySTEntryObject *ste) |
588 | | -{ |
589 | | - return _PyST_IsFunctionLike(ste) || ste->ste_type == InlinedComprehensionBlock; |
590 | | -} |
591 | | - |
592 | 590 | static int |
593 | 591 | error_at_directive(PySTEntryObject *ste, PyObject *name) |
594 | 592 | { |
@@ -1321,7 +1319,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free, |
1321 | 1319 | /* Populate global and bound sets to be passed to children. */ |
1322 | 1320 | if (ste->ste_type != ClassBlock) { |
1323 | 1321 | /* Add function locals to bound set */ |
1324 | | - if (ste_binds_locals_for_children(ste)) { |
| 1322 | + if (ste_uses_fast_locals(ste)) { |
1325 | 1323 | temp = PyNumber_InPlaceOr(newbound, local); |
1326 | 1324 | if (!temp) |
1327 | 1325 | goto error; |
@@ -1409,7 +1407,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free, |
1409 | 1407 | } |
1410 | 1408 |
|
1411 | 1409 | /* Check if any local variables must be converted to cell variables */ |
1412 | | - if (ste_binds_locals_for_children(ste) && !analyze_cells(scopes, newfree, inlined_cells)) { |
| 1410 | + if (ste_uses_fast_locals(ste) && !analyze_cells(scopes, newfree, inlined_cells)) { |
1413 | 1411 | goto error; |
1414 | 1412 | } |
1415 | 1413 | else if (ste->ste_type == ClassBlock && !drop_class_free(ste, newfree)) { |
@@ -2690,7 +2688,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e) |
2690 | 2688 | return 0; |
2691 | 2689 | } |
2692 | 2690 | if (!allows_top_level_await(st)) { |
2693 | | - if (!ste_binds_locals_for_children(st->st_cur)) { |
| 2691 | + if (!ste_uses_fast_locals(st->st_cur)) { |
2694 | 2692 | PyErr_SetString(PyExc_SyntaxError, |
2695 | 2693 | "'await' outside function"); |
2696 | 2694 | SET_ERROR_LOCATION(st->st_filename, LOCATION(e)); |
@@ -2768,8 +2766,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e) |
2768 | 2766 | } |
2769 | 2767 | /* Special-case super: it counts as a use of __class__ */ |
2770 | 2768 | if (e->v.Name.ctx == Load && |
2771 | | - (_PyST_IsFunctionLike(st->st_cur) || |
2772 | | - st->st_cur->ste_type == InlinedComprehensionBlock) && |
| 2769 | + ste_uses_fast_locals(st->st_cur) && |
2773 | 2770 | _PyUnicode_EqualToASCIIString(e->v.Name.id, "super")) { |
2774 | 2771 | if (!symtable_add_def(st, &_Py_ID(__class__), USE, LOCATION(e))) |
2775 | 2772 | return 0; |
|
0 commit comments