-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
gh-123881: make compiler add the .generic_base base class without constructing AST nodes #123883
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
Changes from 5 commits
031c697
6547576
412fe99
781fc79
8200b77
d75532a
22228eb
4831765
5218173
0e52c0f
341f8a5
e92c432
40046c1
4611b92
c6c3cff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| The ``.generic_base`` base class of generic classes is now added by the | ||
| parser rather than the compiler. This means that it is visible in the | ||
| ``AST``. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,6 @@ typedef struct _PyCompiler compiler; | |
| #define SCOPE_TYPE(C) _PyCompile_ScopeType(C) | ||
| #define QUALNAME(C) _PyCompile_Qualname(C) | ||
| #define METADATA(C) _PyCompile_Metadata(C) | ||
| #define ARENA(C) _PyCompile_Arena(C) | ||
|
|
||
| typedef _PyInstruction instruction; | ||
| typedef _PyInstructionSequence instr_sequence; | ||
|
|
@@ -1549,27 +1548,8 @@ codegen_class(compiler *c, stmt_ty s) | |
| ADDOP_I_IN_SCOPE(c, loc, CALL_INTRINSIC_1, INTRINSIC_SUBSCRIPT_GENERIC); | ||
| RETURN_IF_ERROR_IN_SCOPE(c, codegen_nameop(c, loc, &_Py_STR(generic_base), Store)); | ||
|
|
||
| Py_ssize_t original_len = asdl_seq_LEN(s->v.ClassDef.bases); | ||
| asdl_expr_seq *bases = _Py_asdl_expr_seq_new( | ||
| original_len + 1, ARENA(c)); | ||
| if (bases == NULL) { | ||
| _PyCompile_ExitScope(c); | ||
| return ERROR; | ||
| } | ||
| for (Py_ssize_t i = 0; i < original_len; i++) { | ||
| asdl_seq_SET(bases, i, asdl_seq_GET(s->v.ClassDef.bases, i)); | ||
| } | ||
| expr_ty name_node = _PyAST_Name( | ||
| &_Py_STR(generic_base), Load, | ||
| loc.lineno, loc.col_offset, loc.end_lineno, loc.end_col_offset, ARENA(c) | ||
| ); | ||
| if (name_node == NULL) { | ||
| _PyCompile_ExitScope(c); | ||
| return ERROR; | ||
| } | ||
| asdl_seq_SET(bases, original_len, name_node); | ||
| RETURN_IF_ERROR_IN_SCOPE(c, codegen_call_helper(c, loc, 2, | ||
| bases, | ||
| s->v.ClassDef.bases, | ||
|
||
| s->v.ClassDef.keywords)); | ||
|
|
||
| PyCodeObject *co = _PyCompile_OptimizeAndAssemble(c, 0); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.