Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-130881: Handle conditionally defined annotations #130935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tweaks
  • Loading branch information
JelleZijlstra committed Mar 14, 2025
commit ed79a88cda76e2e6925c679a03896c0aae41b089
2 changes: 2 additions & 0 deletions 2 Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ _PyCompile_EnterConditionalBlock(struct _PyCompiler *c)
void
_PyCompile_LeaveConditionalBlock(struct _PyCompiler *c)
{
assert(c->u->u_in_conditional_block > 0);
c->u->u_in_conditional_block--;
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -1166,6 +1167,7 @@ _PyCompile_AddDeferredAnnotation(compiler *c, stmt_ty s,
Py_DECREF(index);
return ERROR;
}
Py_DECREF(index);
return SUCCESS;
}

Expand Down
3 changes: 2 additions & 1 deletion 3 Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -2730,7 +2730,8 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation, void *key)
{
if ((st->st_cur->ste_type == ClassBlock || st->st_cur->ste_type == ModuleBlock)
&& st->st_cur->ste_in_conditional_block
&& !st->st_cur->ste_has_conditional_annotations) {
&& !st->st_cur->ste_has_conditional_annotations)
{
st->st_cur->ste_has_conditional_annotations = 1;
if (!symtable_add_def(st, &_Py_ID(__conditional_annotations__), USE, LOCATION(annotation))) {
return 0;
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.