mgorny added inline comments.

================
Comment at: tools/clang-format/git-clang-format:306
+    try:
+        return to_string(bytes.decode('utf-8'))
+    except AttributeError: # 'str' object has no attribute 'decode'.
----------------
EricWF wrote:
> mgorny wrote:
> > This logic looks really weird to me. What is the purpose of having both 
> > `to_string()` and `convert_string()`? Why do `to_bytes()` and `to_string()` 
> > use `isinstance()` to recognize types, and here you rely on exceptions? Why 
> > is `to_string()` called after decoding?
> `to_string` is called after decoding because in python2 the result of 
> decoding is a `unicode` type, and we need to encode it a `str` type. Hense 
> to_string.
No offense intended but this sounds really horrible. In modern Python, 
everything is either `bytes` or `unicode`. The difference basically is that 
`str` in py2 was pretty much `bytes` (except that `bytes` explicitly removes 
some operations that are unsuitable for bytestrings), and that `str` in py3 is 
equivalent to `unicode` before.

So if you are specifically converting to `str`, it means that you want to have 
two distinct types in py2/py3. Which really sounds like you're doing something 
wrong.


https://reviews.llvm.org/D30773



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to