-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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 1 commit
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
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1949,6 +1949,26 @@ compiler_default_arguments(struct compiler *c, arguments_ty args) | |
return funcflags; | ||
} | ||
|
||
static int corrected_firstlineno(struct compiler *c, stmt_ty s, | ||
asdl_seq * decos) | ||
{ | ||
/* To keep the ability to get the relevant source of a decorated item | ||
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. Us 4 spaces for indentation. |
||
using inspect.getsource, we need to keep the first line number | ||
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. Align wrapped lines to "To keep", not to "/*". |
||
of the code object as the first line number of the first decorator. | ||
This used to be done via the AST, but it is better to hide this | ||
internally. | ||
*/ | ||
if (asdl_seq_LEN(decos) > 0) { | ||
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.
|
||
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. Seems Add a regression test for these cases: def f():
@deco
def g(): pass class A:
@deco
def m(self): pass 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.
I'm probably missing something, but the generated AST is:
which seems correct. Perhaps I am misunderstanding? |
||
return first_decorator->lineno; | ||
} | ||
else { | ||
return s->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. This empty line is unnecessary. |
||
} | ||
|
||
static int | ||
compiler_function(struct compiler *c, stmt_ty s, int is_async) | ||
{ | ||
|
@@ -1988,11 +2008,9 @@ 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. Too many empty lines. |
||
int first_lineno = corrected_firstlineno(c, s, decos); | ||
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. Indentation is misleading, shift left. |
||
|
||
|
||
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) { | ||
|
@@ -2007,7 +2025,7 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async) | |
funcflags |= 0x04; | ||
} | ||
|
||
if (!compiler_enter_scope(c, name, scope_type, (void *)s, s->lineno)) { | ||
if (!compiler_enter_scope(c, name, scope_type, (void *)s, first_lineno)) { | ||
return 0; | ||
} | ||
|
||
|
@@ -2056,6 +2074,8 @@ compiler_class(struct compiler *c, stmt_ty s) | |
if (!compiler_decorators(c, decos)) | ||
return 0; | ||
|
||
int first_lineno = corrected_firstlineno(c, s, decos); | ||
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. Wrong indentation. |
||
|
||
/* ultimately generate code for: | ||
<name> = __build_class__(<func>, <name>, *<bases>, **<keywords>) | ||
where: | ||
|
@@ -2070,7 +2090,7 @@ compiler_class(struct compiler *c, stmt_ty s) | |
|
||
/* 1. compile the class body into a code object */ | ||
if (!compiler_enter_scope(c, s->v.ClassDef.name, | ||
COMPILER_SCOPE_CLASS, (void *)s, s->lineno)) | ||
COMPILER_SCOPE_CLASS, (void *)s, first_lineno)) | ||
return 0; | ||
/* this block represents what we do in the new scope */ | ||
{ | ||
|
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 weird indentation on a separate line?
Uh oh!
There was an error while loading. Please reload this page.
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.
I think patchcheck messed up some of this up, sorry for the noise.
On the
Py_UNREACHABLE()
line, I originally had double tab indentation (I forgot to change Visual Studio's settings), and its seemed to change that to triple groups of 4 spaces, so I'm guessing when I ran patchcheck it caused other problems. I'll manually verify in future.