bpo-33211: Change line number of decorated nodes back to def#6460
bpo-33211: Change line number of decorated nodes back to def#6460emmatyping wants to merge 19 commits into
Conversation
ilevkivskyi
left a comment
There was a problem hiding this comment.
Few comments. Also watch out, this PR will get merge conflicts pretty often.
Sorry, something went wrong.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
What about classes? Does they need correcting the first line number?
Please add test for AST line numbers.
Sorry, something went wrong.
Yes, I just added the same change that happens in
I am planning on doing so. I want things to pass existing tests in CI first however. |
Sorry, something went wrong.
|
Okay, looks like test_dis and test_inspect passed, so I will get to writing new tests for decorated nodes in test_ast. Done! Ready for review. |
Sorry, something went wrong.
ilevkivskyi
left a comment
There was a problem hiding this comment.
This is almost ready.
Sorry, something went wrong.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
It may be worth to add a note about this change in the "Whats New" document.
Sorry, something went wrong.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
The generated AST is correct, the generated code is wrong. Look at f.__code__.co_firstlineno in
def f():
@deco
def g(): passand
def f():
@deco
class A: pass
Sorry, something went wrong.
Thank you for catching this. I've added tests to both test_ast and test_inspect to make sure the AST and inspect.getsource don't regress. Also, I believe I have responded to all of your feedback. Thank you! |
Sorry, something went wrong.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Why there are changes in Python/importlib.h and Python/importlib_external.h? I thought the purpose of this PR is changing line numbers in AST, but keeping the bytecode unchanged.
Sorry, something went wrong.
Yes, that is concerning. I think I will take a closer look at what is going on. W.R.T your comments on So based on these I think I need to figure out what is actually going on before I proceed, I still have much to learn about the compiler's intricacies. |
Sorry, something went wrong.
|
Um, it seems you still need to act on the comment from 5 days ago? |
Sorry, something went wrong.
Ah, yes I haven't pushed anything because I haven't found out why the generated bytecode is different yet. I will once I figure things out more. |
Sorry, something went wrong.
|
Sorry this is temorarily stalled until I can get my computer working again... |
Sorry, something went wrong.
|
@serhiy-storchaka What do you think? Is it ready to be merged? I don't suppose this can make it into 3.7, since IIUC the breakage is pretty noticeable. |
Sorry, something went wrong.
|
If I understand it correctly, the bytecode shouldn't be affected by this PR. But the frozen bytecode is changed, and I don't understand the cause. Either there is a bug in the code generation introduced by this PR, or my understanding is wrong. I like this PR in general and hope Ethan and me will found the cause. |
Sorry, something went wrong.
Yes, this is correct. I am going to try to spend more time today trying to understand why it changes the bytecode. |
Sorry, something went wrong.
|
@ethanhs |
Sorry, something went wrong.
|
@ilevkivskyi Serhiy asked me to see if there was anything useful in this PR that could be pulled out in the original issue https://bugs.python.org/issue33211#msg330181 (He accidentally redid this work on his own). I don't see anything that would be beneficial that is in this PR and not in #9731, so I will close this. |
Sorry, something went wrong.
This change moves the patching of decorated defs from the publicly used AST to the private bytecode.
This has the advantage that decorated defs in the ast keep their line numbers correctly, but
inspect.getsourceshould still work.https://bugs.python.org/issue33211