r285301 - Attempt to make clang-format.py python 3 - compatible.

Vedant Kumar via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 6 21:59:03 PST 2016


Hi Alexander,

I think this will cause an error if used with python3 (at least, it fails on my
system). Here's the problem:

  line.decode(encoding)

When vim is compiled against python3, the type of 'line' remains 'str' -- not
'bytes'. There isn't a 'decode' method on strings: it only exists for bytes. I
take this to mean that vim has done the decoding already. If not, there's a bug
in vim.

I've attached a small patch that addresses this issue. Wdyt?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: cf.patch
Type: application/octet-stream
Size: 921 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161206/af13f40d/attachment.obj>
-------------- next part --------------


thanks,
vedant


> On Oct 27, 2016, at 8:15 AM, Alexander Kornienko via cfe-commits <cfe-commits at lists.llvm.org> wrote:
> 
> Author: alexfh
> Date: Thu Oct 27 10:15:23 2016
> New Revision: 285301
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=285301&view=rev
> Log:
> Attempt to make clang-format.py python 3 - compatible.
> 
> Modified:
>    cfe/trunk/tools/clang-format/clang-format.py
> 
> Modified: cfe/trunk/tools/clang-format/clang-format.py
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.py?rev=285301&r1=285300&r2=285301&view=diff
> ==============================================================================
> --- cfe/trunk/tools/clang-format/clang-format.py (original)
> +++ cfe/trunk/tools/clang-format/clang-format.py Thu Oct 27 10:15:23 2016
> @@ -51,7 +51,7 @@ if vim.eval('exists("g:clang_format_fall
> def main():
>   # Get the current text.
>   encoding = vim.eval("&encoding")
> -  buf = [ unicode(line, encoding) for line in vim.current.buffer ]
> +  buf = [ line.decode(encoding) for line in vim.current.buffer ]
>   text = '\n'.join(buf)
> 
>   # Determine range to format.
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list