diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2025-04-28 06:10:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-28 06:10:28 -0700 |
commit | 922049b613d155ade4c4a8f83452767bea003a9f (patch) | |
tree | c466659499780de432b0d77a803d3adfbe739174 /Python/symtable.c | |
parent | 5bf0f3666e272798789ff900b1071760c73b46fd (diff) | |
download | cpython-922049b613d155ade4c4a8f83452767bea003a9f.tar.gz cpython-922049b613d155ade4c4a8f83452767bea003a9f.zip |
gh-130907: Treat all module-level annotations as conditional (#131550)
Diffstat (limited to 'Python/symtable.c')
-rw-r--r-- | Python/symtable.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Python/symtable.c b/Python/symtable.c index 66f6c4a89aa..2f13f35072a 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -2749,8 +2749,10 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation, void *key) // Annotations in local scopes are not executed and should not affect the symtable bool is_unevaluated = st->st_cur->ste_type == FunctionBlock; - if ((st->st_cur->ste_type == ClassBlock || st->st_cur->ste_type == ModuleBlock) - && st->st_cur->ste_in_conditional_block + // Module-level annotations are always considered conditional because the module + // may be partially executed. + if ((((st->st_cur->ste_type == ClassBlock && st->st_cur->ste_in_conditional_block) + || st->st_cur->ste_type == ModuleBlock)) && !st->st_cur->ste_has_conditional_annotations) { st->st_cur->ste_has_conditional_annotations = 1; |