kaitingwang created this revision. kaitingwang added reviewers: djasper, sammccall, ldrumm, vsk. kaitingwang added a project: clang-format. Herald added subscribers: Naghasan, Anastasia. Herald added a project: All. kaitingwang requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
>From Python 3.6 and above, it should be able to automatically select a >decoding for the json.loads. However, with a vim encoding that defaults to >utf-8, the clang-format.py runs into the following error. The patch explicit >specifies to use use utf-8 decoding for head. Traceback (most recent call last): File "<string>", line 1, in <module> File "/home/k00375917/sycl_workspace/llvm/clang/tools/clang-format/clang-format.py", line 156, in <module> main() File "/home/k00375917/sycl_workspace/llvm/clang/tools/clang-format/clang-format.py", line 137, in main header = json.loads(header) File "/usr/lib/python3.5/json/__init__.py", line 312, in loads s.__class__.__name__)) TypeError: the JSON object must be str, not 'bytes' Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D133236 Files: clang/tools/clang-format/clang-format.py Index: clang/tools/clang-format/clang-format.py =================================================================== --- clang/tools/clang-format/clang-format.py +++ clang/tools/clang-format/clang-format.py @@ -10,9 +10,9 @@ # imap <C-I> <c-o>:py3f <path-to-this-file>/clang-format.py<cr> # endif # -# The if-elseif-endif conditional should pick either the python3 or python2 +# The if-elseif-endif conditional should pick either the python3 or python2 # integration depending on your vim setup. -# +# # The first mapping enables clang-format for NORMAL and VISUAL mode, the second # mapping adds support for INSERT mode. Change "C-I" to another binding if you # need clang-format on a different key (C-I stands for Ctrl+i). @@ -134,7 +134,7 @@ ) else: header, content = stdout.split(b'\n', 1) - header = json.loads(header) + header = json.loads(header.decode('utf-8')) # Strip off the trailing newline (added above). # This maintains trailing empty lines present in the buffer if # the -lines specification requests them to remain unchanged.
Index: clang/tools/clang-format/clang-format.py =================================================================== --- clang/tools/clang-format/clang-format.py +++ clang/tools/clang-format/clang-format.py @@ -10,9 +10,9 @@ # imap <C-I> <c-o>:py3f <path-to-this-file>/clang-format.py<cr> # endif # -# The if-elseif-endif conditional should pick either the python3 or python2 +# The if-elseif-endif conditional should pick either the python3 or python2 # integration depending on your vim setup. -# +# # The first mapping enables clang-format for NORMAL and VISUAL mode, the second # mapping adds support for INSERT mode. Change "C-I" to another binding if you # need clang-format on a different key (C-I stands for Ctrl+i). @@ -134,7 +134,7 @@ ) else: header, content = stdout.split(b'\n', 1) - header = json.loads(header) + header = json.loads(header.decode('utf-8')) # Strip off the trailing newline (added above). # This maintains trailing empty lines present in the buffer if # the -lines specification requests them to remain unchanged.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits