-
-
Notifications
You must be signed in to change notification settings - Fork 427
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
Tentative fix for #439 #451
Conversation
This looks good. Since this is so simple, would you do just a little more and include a test for this? One place a check could be added is to the existing test Additional code might be: # Check that we can distinguish names from strings in literal collections, e.g. lists.
# The list has to have more than 4 items go get accumulated in a collection
a = ["y", 'Exception', "x", Exception, "z"]
assert a[1] == "Exception"
assert a[3] == Exception To update the existing bytecode in ./add-test.py -r test/simple_source/expression/05_long_literals.py |
Done and done. |
|
||
|
||
# Check that we can distinguish names from strings in literal collections, e.g. lists. | ||
# The list has to have more than 4 items go get accumulated in a collection |
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.
go get -> to get
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.
Fixed
for j in range(collection_start, i): | ||
if tokens[j] == "LOAD_CONST": |
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 now realize that while this is necessary, it probably is not sufficient. There may be constants that are code blocks.
However we can start at this and if you are up for it see if we can find those kinds of things that use LOAD_CONST with non-string items in another PR.
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.
LGTM and thanks. There still may be some edge cases to work out which is noted in the comment.
@andrem-eberle Actually I just tried this out and this has problems. The bottom of the decompilation looks like this: a = [
"'y'", "'Exception'", "'x'", 'Exception', "'z'"] There are extra quotes. Also, the To get back the assert put the assert with the As for the extra quotes, that is somewhere in semantics actions. |
This is odd, I can't seem to reproduce the extra quotes here, using latest xdis version and the forked uncompyle6. I am using the pip version of spark, could it be related? |
Probably not spark related. And the problem is not in I also tried running from Python 3.8 (and not 3.8). When I get a chance I will try to see where I am getting the extra quotes. However in disassembly I can definitely see that the assert statements are gone in the bytecode. |
Ah I see. Sorry I have been focusing on 2.7, forgot about 3.x entirely. It does decompile wrong for code compiled with 3.8. In fact, the else block is decompiled wrong here in 3.8 (the values is inserted into the else), which means the test doesn't fail anyway (even with forced asserts), since it never gets into the else. The Exception test is also inside the else in the decompiled version:
I will look into the extra quotes. |
Well the cause is the str.__repr__() method, it adds the quotes in 3.8 but not in 2.7 (which is why I wasn't seeing this error in 2.7). One option is to check for python source version in n_actions.py and use repr() or str(), I did some test here and it worked. Is this kind of solution acceptable for you? If so I will add another pull request. |
Yes, this is good - thanks. |
I altered the code on scanner.py a bit, to separate CONST from NAME vars, in fact it seems it already had this part, but was garbled outside the loop?