8000 gh-130907: Treat all module-level annotations as conditional by JelleZijlstra · Pull Request #131550 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-130907: Treat all module-level annotations as conditional #131550

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 13 commits into from
Apr 28, 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
rename
  • Loading branch information
JelleZijlstra committed Apr 9, 2025
commit 137cea703c815c9576c9a9c2bd0c8ca6924507e5
4 changes: 2 additions & 2 deletions Include/internal/pycore_instruction_sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ _PyJumpTargetLabel _PyInstructionSequence_NewLabel(_PyInstructionSequence *seq);
int _PyInstructionSequence_ApplyLabelMap(_PyInstructionSequence *seq);
int _PyInstructionSequence_InsertInstruction(_PyInstructionSequence *seq, int pos,
int opcode, int oparg, _Py_SourceLocation loc);
int _PyInstructionSequence_PrependSequence(_PyInstructionSequence *seq, int pos,
_PyInstructionSequence *nested);
int _PyInstructionSequence_InjectSequence(_PyInstructionSequence *seq, int pos,
_PyInstructionSequence *injected);
int _PyInstructionSequence_AddNested(_PyInstructionSequence *seq, _PyInstructionSequence *nested);
void PyInstructionSequence_Fini(_PyInstructionSequence *seq);

Expand Down
2 changes: 1 addition & 1 deletion Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ codegen_process_deferred_annotations(compiler *c, location loc)

if (nested_instr_seq != NULL) {
RETURN_IF_ERROR(
_PyInstructionSequence_PrependSequence(old_instr_seq, 1, nested_instr_seq));
_PyInstructionSequence_InjectSequence(old_instr_seq, 1, nested_instr_seq));
_PyCompile_SetInstrSequence(c, old_instr_seq);
PyInstructionSequence_Fini(nested_instr_seq);
}
Expand Down
20 changes: 10 additions & 10 deletions Python/instruction_sequence.c
5CD6
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,27 @@ _PyInstructionSequence_InsertInstruction(instr_sequence *seq, int pos,
}

int
_PyInstructionSequence_PrependSequence(instr_sequence *seq, int pos,
instr_sequence *nested)
_PyInstructionSequence_InjectSequence(instr_sequence *seq, int pos,
instr_sequence *injected)
{
assert(pos >= 0 && pos <= seq->s_used);
// Merging labelmaps is not supported
assert(nested->s_labelmap_size == 0 && nested->s_nested == NULL);
if (nested->s_used == 0) {
assert(injected->s_labelmap_size == 0 && injected->s_nested == NULL);
if (injected->s_used == 0) {
return SUCCESS;
}

int last_idx = instr_sequence_grow(seq, nested->s_used);
int last_idx = instr_sequence_grow(seq, injected->s_used);

RETURN_IF_ERROR(last_idx);
for (int i = last_idx - nested->s_used; i >= pos; i--) {
seq->s_instrs[i + nested->s_used] = seq->s_instrs[i];
for (int i = last_idx - injected->s_used; i >= pos; i--) {
seq->s_instrs[i + injected->s_used] = seq->s_instrs[i];
}
for (int i=0; i < nested->s_used; i++) {
seq->s_instrs[i + pos] = nested->s_instrs[i];
for (int i=0; i < injected->s_used; i++) {
seq->s_instrs[i + pos] = injected->s_instrs[i];
}
for(int lbl=0; lbl < seq->s_labelmap_size; lbl++) {
seq->s_labelmap[lbl] += nested->s_used;
seq->s_labelmap[lbl] += injected->s_used;
}
return SUCCESS;
}
Expand Down
Loading
0