-
-
You must be signed in to change notification settings -
bpo-33211: Change line number of decorated nodes back to def #6460
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 7 commits
b60b6a6
ae578b0
191bd38
da42832
649506c
29b0d60
68b2228
09d8ab2
df9fbe2
9840f84
0842c20
7f4fcdf
e4e7f1a
a8e747d
3df5862
44a3cd9
afd3b7e
bdc9942
914d0a0
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 @@ | ||
Change the line number of decorated defs back to the def or class token in the | ||
AST, not the first decorator. Have the change of line number happen in the | ||
compiler. | ||
There was a problem hiding this comment. Choose a reason for hiding this 8000 commentThe reason will be displayed to describe this comment to others. Learn more. Please add "Patch by *yourname"." And add your name in Misc/ACKS. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1672,7 +1672,6 @@ static stmt_ty | |
ast_for_decorated(struct compiling *c, const node *n) | ||
{ | ||
/* decorated: decorators (classdef | funcdef | async_funcdef) */ | ||
stmt_ty thing = NULL; | ||
asdl_seq *decorator_seq = NULL; | ||
|
||
REQ(n, decorated); | ||
|
@@ -1686,19 +1685,14 @@ ast_for_decorated(struct compiling *c, const node *n) | |
TYPE(CHILD(n, 1)) == classdef); | ||
|
||
if (TYPE(CHILD(n, 1)) == funcdef) { | ||
thing = ast_for_funcdef(c, CHILD(n, 1), decorator_seq); | ||
return ast_for_funcdef(c, CHILD(n, 1), decorator_seq); | ||
} else if (TYPE(CHILD(n, 1)) == classdef) { | ||
|
||
thing = ast_for_classdef(c, CHILD(n, 1), decorator_seq); | ||
return ast_for_classdef(c, CHILD(n, 1), decorator_seq); | ||
} else if (TYPE(CHILD(n, 1)) == async_funcdef) { | ||
thing = ast_for_async_funcdef(c, CHILD(n, 1), decorator_seq); | ||
} | ||
/* we count the decorators in when talking about the class' or | ||
* function's line number */ | ||
if (thing) { | ||
thing->lineno = LINENO(n); | ||
thing->col_offset = n->n_col_offset; | ||
return ast_for_async_funcdef(c, CHILD(n, 1), decorator_seq); | ||
} else { | ||
return NULL; // should never ever happen | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still not fixed. |
||
} | ||
return thing; | ||
} | ||
|
||
static expr_ty | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1982,6 +1982,12 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async) | |
if (!compiler_decorators(c, decos)) | ||
return 0; | ||
|
||
// fixup decorators to be the first line number internally. | ||
if (asdl_seq_LEN(decos) > 0) { | ||
expr_ty first_decorator = asdl_seq_GET(decos, 0); | ||
c->u->u_firstlineno = first_decorator->lineno; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this is needed? It would be a bit awkward if we externally show everywhere line of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, I think it may be OK if you give a good comment with an explanation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to maintain the first line number of the code object to be the line number of the first decorator so that |
||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too many empty lines |
||
funcflags = compiler_default_arguments(c, args); | ||
if (funcflags == -1) { | ||
return 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this is changed? I thought this PR shouldn't change
__code__.co_firstlineno
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing this out. I realized that my changes weren't actually updating the first line number in the compiler! I've fixed that.