Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Update cpplint.py for compatibility with Python 3 #576

Closed
wants to merge 1 commit into from

Conversation

cclauss
Copy link

@cclauss cclauss commented Jul 23, 2018

xrange() was removed in Python 3 in favor of range(). This PR ensures similar functionality on both Python 2 and Python 3.

Similar to nodejs/nan#797

Discovered via https://travis-ci.com/nodejs/node/builds/79706150 (nodejs/node#21942)

flake8 testing of https://github.com/nodejs/node-chakracore on Python 3.7.0

$ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics

./tools/cpplint.py:1471:12: F821 undefined name 'xrange'
  for i in xrange(startpos, len(line)):
           ^
./tools/cpplint.py:1700:15: F821 undefined name 'xrange'
  for line in xrange(1, min(len(lines), 11)):
              ^
./tools/cpplint.py:1828:12: F821 undefined name 'xrange'
  for i in xrange(1, len(raw_lines) - 1):
           ^
./tools/cpplint.py:2169:14: F821 undefined name 'xrange'
    for i in xrange(linenum - 1, self.starting_linenum, -1):
             ^
./tools/cpplint.py:2950:26: F821 undefined name 'xrange'
    for start_linenum in xrange(linenum, clean_lines.NumLines()):
                         ^
./tools/cpplint.py:3437:14: F821 undefined name 'xrange'
    for i in xrange(first_line, last_line + 1, 1):
             ^
./tools/cpplint.py:3501:19: F821 undefined name 'xrange'
    for offset in xrange(endlinenum + 1,
                  ^
./tools/cpplint.py:4047:14: F821 undefined name 'xrange'
    for i in xrange(linenum + 1, end_line):
             ^
./tools/cpplint.py:4218:23: F821 undefined name 'unicode'
  if isinstance(line, unicode):
                      ^
./tools/cpplint.py:4870:12: F821 undefined name 'xrange'
  for i in xrange(linenum, max(-1, linenum - 10), -1):
           ^
./tools/cpplint.py:4891:12: F821 undefined name 'xrange'
  for i in xrange(linenum, max(-1, linenum - 10), -1):
           ^
./tools/cpplint.py:4907:12: F821 undefined name 'xrange'
  for i in xrange(linenum, 1, -1):
           ^
./tools/cpplint.py:5008:20: F821 undefined name 'xrange'
          for i in xrange(startline, linenum + 1):
                   ^
./tools/cpplint.py:5032:14: F821 undefined name 'xrange'
    for i in xrange(linenum - 1, max(0, linenum - 10), -1):
             ^
./tools/cpplint.py:5063:14: F821 undefined name 'xrange'
    for i in xrange(2):
             ^
./tools/cpplint.py:5226:14: F821 undefined name 'xrange'
    for i in xrange(linenum - 1, max(0, linenum - 5), -1):
             ^
./tools/cpplint.py:5442:18: F821 undefined name 'xrange'
  for linenum in xrange(clean_lines.NumLines()):
                 ^
./tools/cpplint.py:5573:21: F821 undefined name 'xrange'
  for start_line in xrange(linenum, min(linenum + 3, clean_lines.NumLines())):
                    ^
./tools/cpplint.py:5588:12: F821 undefined name 'xrange'
  for i in xrange(end_line, min(end_line + 3, clean_lines.NumLines())):
           ^
./tools/cpplint.py:5845:15: F821 undefined name 'xrange'
  for line in xrange(clean_lines.NumLines()):
              ^
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

__xrange()__ was removed in Python 3 in favor of __range()__.  This PR ensures similar functionality on both Python 2 and Python 3.

Similar to nodejs/nan#797

Discovered via https://travis-ci.com/nodejs/node/builds/79706150 (nodejs/node#21942)


flake8 testing of https://github.com/nodejs/node-chakracore on Python 3.7.0

$ __flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics__
```
./tools/cpplint.py:1471:12: F821 undefined name 'xrange'
  for i in xrange(startpos, len(line)):
           ^
./tools/cpplint.py:1700:15: F821 undefined name 'xrange'
  for line in xrange(1, min(len(lines), 11)):
              ^
./tools/cpplint.py:1828:12: F821 undefined name 'xrange'
  for i in xrange(1, len(raw_lines) - 1):
           ^
./tools/cpplint.py:2169:14: F821 undefined name 'xrange'
    for i in xrange(linenum - 1, self.starting_linenum, -1):
             ^
./tools/cpplint.py:2950:26: F821 undefined name 'xrange'
    for start_linenum in xrange(linenum, clean_lines.NumLines()):
                         ^
./tools/cpplint.py:3437:14: F821 undefined name 'xrange'
    for i in xrange(first_line, last_line + 1, 1):
             ^
./tools/cpplint.py:3501:19: F821 undefined name 'xrange'
    for offset in xrange(endlinenum + 1,
                  ^
./tools/cpplint.py:4047:14: F821 undefined name 'xrange'
    for i in xrange(linenum + 1, end_line):
             ^
./tools/cpplint.py:4218:23: F821 undefined name 'unicode'
  if isinstance(line, unicode):
                      ^
./tools/cpplint.py:4870:12: F821 undefined name 'xrange'
  for i in xrange(linenum, max(-1, linenum - 10), -1):
           ^
./tools/cpplint.py:4891:12: F821 undefined name 'xrange'
  for i in xrange(linenum, max(-1, linenum - 10), -1):
           ^
./tools/cpplint.py:4907:12: F821 undefined name 'xrange'
  for i in xrange(linenum, 1, -1):
           ^
./tools/cpplint.py:5008:20: F821 undefined name 'xrange'
          for i in xrange(startline, linenum + 1):
                   ^
./tools/cpplint.py:5032:14: F821 undefined name 'xrange'
    for i in xrange(linenum - 1, max(0, linenum - 10), -1):
             ^
./tools/cpplint.py:5063:14: F821 undefined name 'xrange'
    for i in xrange(2):
             ^
./tools/cpplint.py:5226:14: F821 undefined name 'xrange'
    for i in xrange(linenum - 1, max(0, linenum - 5), -1):
             ^
./tools/cpplint.py:5442:18: F821 undefined name 'xrange'
  for linenum in xrange(clean_lines.NumLines()):
                 ^
./tools/cpplint.py:5573:21: F821 undefined name 'xrange'
  for start_line in xrange(linenum, min(linenum + 3, clean_lines.NumLines())):
                    ^
./tools/cpplint.py:5588:12: F821 undefined name 'xrange'
  for i in xrange(end_line, min(end_line + 3, clean_lines.NumLines())):
           ^
./tools/cpplint.py:5845:15: F821 undefined name 'xrange'
  for line in xrange(clean_lines.NumLines()):
              ^
```
@MSLaguana
Copy link
Contributor

Thanks for the PR! This file looks to be unchanged from the upstream https://github.com/nodejs/node repository, so rather than introducing an unnecessary difference in our fork, could you please open an equivalent PR against them? We'll get the change after it merges in as part of our regular updates from upstream, and this way the greater nodejs community gets the benefit.

@cclauss
Copy link
Author

cclauss commented Jul 23, 2018

Made in upstream https://github.com/nodejs/node

@cclauss cclauss closed this Jul 23, 2018
@cclauss cclauss deleted the patch-1 branch July 23, 2018 16:53
@MSLaguana
Copy link
Contributor

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants