Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cpplint/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
import sys
import unicodedata

try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer an explicit version check rather than an exception, something like this:

if sys.version_info >= (3,):
  xrange = range  # xrange is only used on for loops so this is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Python porting best practice is Use feature detection instead of version detection.

xrange # Python 2
except NameError:
xrange = range # Python 3


_USAGE = """
Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
Expand Down
5 changes: 5 additions & 0 deletions cpplint/cpplint_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@

import cpplint

try:
xrange # Python 2
except NameError:
xrange = range # Python 3


# This class works as an error collector and replaces cpplint.Error
# function for the unit tests. We also verify each category we see
Expand Down