-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Add Python3 Support of cpplint.py and cpplint_unittest.py #349
base: gh-pages
Are you sure you want to change the base?
Conversation
1. After alias unicode to str and replace iteritems, itervalues, cpplint.py can work well under Python3 if the linted file hasn't any problem. But if there is even only one violation of Google C++ Style Guide in linted file, cpplint.py will need to output error message, then exception like "TypeError: write() argument must be str, not bytes" will appear. This issue is caused by different supporting methods of Unicode between Python2 and Python3, in Python2 type "str" actually is bytes sequence, type "unicode" is used to handle Unicode string, but in Python3 type "str" definitely is Unicode sequence, so type "unicode" hasn't any value and be removed, type "bytes" is introduced to handle bytes sequence, so the type "bytes" of Python3 is equal to the type "str" of Python2. The type of argument of sys.stderr.write() is kept same between Python2 and Python3, all are "str", as mentioned above, actually the type of argument of sys.stderr.write() is changed totally. It receive a bytes sequence in Python2 and a Unicode sequence in Python3. So in Python3 sys.stderr shouldn't be wrapped by a UTF-8 stream reader and writer of codecs. 2. Replace assert_ with assertTrue, assertEquals with assertEqual, because assert_ and assertEquals just alias of assertTrue and assertEqual, without this change below message will appear. DeprecationWarning: Please use assertEqual instead. DeprecationWarning: Please use assertTrue instead.
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
I signed it! |
CLAs look good, thanks! |
This patch keeps the bundled cpplint at upstream `43d512b`. Cpplint now works with Python 2 and 3 by adding part of the content of google/styleguide#349. After aliasing `unicode` to `str`, and replacing `iteritems` and `itervalues`, `cpplint.py` can work well with Python 3 if the linted file does not have any issues. If there is even only one style violation in the linted file, `cpplint.py` will need to an output error message, then exceptions like `TypeError: write() argument must be str, not bytes` will appear. This is due to differing Unicode support between Python 2 and 3. In Python 2 `str` is a byte sequence and `unicode` is used to handle Unicode strings, but in Python 3 `str` is a Unicode sequence and `unicode` does not exist. Type `bytes` is introduced to handle bytes sequences, thus Python 3 `bytes` is equal to Python 2 `str`. The type of the argument of `sys.stderr.write()` is kept the same between Python 2 and 3, but the arguments of `sys.stderr.write()` are changed. It receives a byte sequence in Python 2 and a Unicode sequence in Python 3. As a result, `sys.stderr` should not be wrapped by a UTF-8 stream reader and writer of codecs when using Python 3. Review: https://reviews.apache.org/r/67055/
Consider contributing to https://github.com/cpplint/cpplint |
work well under Python3 if the linted file hasn't any problem. But if there
is even only one violation of Google C++ Style Guide in linted file,
cpplint.py will need to output error message, then exception like "TypeError:
write() argument must be str, not bytes" will appear.
This issue is caused by different supporting methods of Unicode between
Python2 and Python3, in Python2 type "str" actually is bytes sequence, type
"unicode" is used to handle Unicode string, but in Python3 type "str"
definitely is Unicode sequence, so type "unicode" hasn't any value and be
removed, type "bytes" is introduced to handle bytes sequence, so the type
"bytes" of Python3 is equal to the type "str" of Python2.
The type of argument of sys.stderr.write() is kept same between Python2 and
Python3, all are "str", as mentioned above, actually the type of argument of
sys.stderr.write() is changed totally. It receive a bytes sequence in Python2
and a Unicode sequence in Python3. So in Python3 sys.stderr shouldn't be
wrapped by a UTF-8 stream reader and writer of codecs.
assert_ and assertEquals just alias of assertTrue and assertEqual, without
this change below message will appear.
DeprecationWarning: Please use assertEqual instead.
DeprecationWarning: Please use assertTrue instead.