Skip to content

Commit 0c2ad7e

Browse files
committed
rename helper and use it in more places
1 parent 045913c commit 0c2ad7e

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

Python/symtable.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@
9191

9292
#define IS_ASYNC_DEF(st) ((st)->st_cur->ste_type == FunctionBlock && (st)->st_cur->ste_coroutine)
9393

94+
static int
95+
ste_uses_fast_locals(PySTEntryObject *ste)
96+
{
97+
return _PyST_IsFunctionLike(ste) || ste->ste_type == InlinedComprehensionBlock;
98+
}
99+
94100
static PySTEntryObject *
95101
ste_new(struct symtable *st, identifier name, _Py_block_ty block,
96102
void *key, _Py_SourceLocation loc)
@@ -130,8 +136,7 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
130136

131137
if (st->st_cur != NULL &&
132138
(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)))
135140
ste->ste_nested = 1;
136141
ste->ste_generator = 0;
137142
ste->ste_coroutine = 0;
@@ -582,13 +587,6 @@ _PyST_IsFunctionLike(PySTEntryObject *ste)
582587
|| ste->ste_type == TypeParametersBlock;
583588
}
584589

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-
592590
static int
593591
error_at_directive(PySTEntryObject *ste, PyObject *name)
594592
{
@@ -1321,7 +1319,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
13211319
/* Populate global and bound sets to be passed to children. */
13221320
if (ste->ste_type != ClassBlock) {
13231321
/* Add function locals to bound set */
1324-
if (ste_binds_locals_for_children(ste)) {
1322+
if (ste_uses_fast_locals(ste)) {
13251323
temp = PyNumber_InPlaceOr(newbound, local);
13261324
if (!temp)
13271325
goto error;
@@ -1409,7 +1407,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
14091407
}
14101408

14111409
/* 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)) {
14131411
goto error;
14141412
}
14151413
else if (ste->ste_type == ClassBlock && !drop_class_free(ste, newfree)) {
@@ -2690,7 +2688,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
26902688
return 0;
26912689
}
26922690
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)) {
26942692
PyErr_SetString(PyExc_SyntaxError,
26952693
"'await' outside function");
26962694
SET_ERROR_LOCATION(st->st_filename, LOCATION(e));
@@ -2768,8 +2766,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
27682766
}
27692767
/* Special-case super: it counts as a use of __class__ */
27702768
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) &&
27732770
_PyUnicode_EqualToASCIIString(e->v.Name.id, "super")) {
27742771
if (!symtable_add_def(st, &_Py_ID(__class__), USE, LOCATION(e)))
27752772
return 0;

0 commit comments

Comments
 (0)