-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Tools/parser/unparse.py does not handle u"bar" correctly #81234
Comments
Currently (135c6a5) the following test fails: ./python -m test.regrtest -v test_tools.test_unparse -u cpu (Note that -u cpu is needed to force test_unparse.DirectoryTestCase to check all files under Lib/ and Lib/test/.) An example error message: ====================================================================== Traceback (most recent call last):
File "/home/yen/Projects/cpython/Lib/test/test_tools/test_unparse.py", line 309, in test_files
self.check_roundtrip(source)
File "/home/yen/Projects/cpython/Lib/test/test_tools/test_unparse.py", line 132, in check_roundtrip
self.assertASTEqual(ast1, ast2)
File "/home/yen/Projects/cpython/Lib/test/test_tools/test_unparse.py", line 124, in assertASTEqual
self.assertEqual(ast.dump(ast1), ast.dump(ast2))
AssertionError: 'Modu[88178 chars]kind=\'u\')], ctx=Load())), ctx=Load()))], dec[421987 chars]=[])' != 'Modu[88178 chars]kind=No
ne)], ctx=Load())), ctx=Load()))], deco[421986 chars]=[])' Apparently that's because Tools/parser/unparse.py does not handle strings like u"bar" correctly. I managed to "fix" it with the following patch: diff --git a/Tools/parser/unparse.py b/Tools/parser/unparse.py
index 385902ef4b..a25b5e49df 100644
--- a/Tools/parser/unparse.py
+++ b/Tools/parser/unparse.py
@@ -399,6 +399,8 @@ class Unparser:
elif value is ...:
self.write("...")
else:
+ if t.kind == 'u':
+ self.write("u")
self._write_constant(t.value) def _List(self, t): Not sure if this is the correct approach, though. |
On the other hand, if this causes troubles, feel free to just replace u"bar" with "bar" in that test. It is not really important. |
Please submit a PR. |
After reading Python/ast.c, I think my patch is correct, so I submitted it to GitHub as #13583 :) |
New changeset aaf47ca by Miss Islington (bot) (Chih-Hsuan Yen) in branch 'master': |
Confirmed that this fixes the broken buildbots: ./python -m test test_tools -vvvv -uall -m test_files Ran 1 test in 0.586s OK == Tests result: SUCCESS == 1 test OK. Total duration: 671 ms The manual check is needed because the CI in GitHub does not run test_tools over all files so it does not take forever. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: