Skip to content
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

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open

Add Python3 Support of cpplint.py and cpplint_unittest.py #349

wants to merge 1 commit into from

Conversation

Johnson9009
Copy link

  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.

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.
@googlebot
Copy link

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. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@Johnson9009
Copy link
Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

asfgit pushed a commit to apache/mesos that referenced this pull request May 18, 2018
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/
@tkruse
Copy link

tkruse commented Oct 29, 2018

Consider contributing to https://github.com/cpplint/cpplint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants