From 7e4c8b9b6b8c57f09513dd3dc6521e7203a12f25 Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 12 Mar 2018 18:13:00 +0100 Subject: [PATCH 1/3] Define xrange() for Python 3 flake8 testing of https://github.com/google/styleguide on Python 3.6.3 $ __flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics__ ``` ./cpplint/cpplint.py:1526:12: F821 undefined name 'xrange' for i in xrange(startpos, len(line)): ^ ./cpplint/cpplint.py:1755:15: F821 undefined name 'xrange' for line in xrange(1, min(len(lines), 11)): ^ ./cpplint/cpplint.py:1957:12: F821 undefined name 'xrange' for i in xrange(1, len(raw_lines) - 1): ^ ./cpplint/cpplint.py:2298:14: F821 undefined name 'xrange' for i in xrange(linenum - 1, self.starting_linenum, -1): ^ ./cpplint/cpplint.py:3080:26: F821 undefined name 'xrange' for start_linenum in xrange(linenum, clean_lines.NumLines()): ^ ./cpplint/cpplint.py:3537:14: F821 undefined name 'xrange' for i in xrange(first_line, last_line + 1, 1): ^ ./cpplint/cpplint.py:3601:19: F821 undefined name 'xrange' for offset in xrange(endlinenum + 1, ^ ./cpplint/cpplint.py:4155:14: F821 undefined name 'xrange' for i in xrange(linenum + 1, end_line): ^ ./cpplint/cpplint.py:4283:23: F821 undefined name 'unicode' if isinstance(line, unicode): ^ ./cpplint/cpplint.py:4928:12: F821 undefined name 'xrange' for i in xrange(linenum, max(-1, linenum - 10), -1): ^ ./cpplint/cpplint.py:4949:12: F821 undefined name 'xrange' for i in xrange(linenum, max(-1, linenum - 10), -1): ^ ./cpplint/cpplint.py:4965:12: F821 undefined name 'xrange' for i in xrange(linenum, 1, -1): ^ ./cpplint/cpplint.py:5066:20: F821 undefined name 'xrange' for i in xrange(startline, linenum + 1): ^ ./cpplint/cpplint.py:5090:14: F821 undefined name 'xrange' for i in xrange(linenum - 1, max(0, linenum - 10), -1): ^ ./cpplint/cpplint.py:5121:14: F821 undefined name 'xrange' for i in xrange(2): ^ ./cpplint/cpplint.py:5284:14: F821 undefined name 'xrange' for i in xrange(linenum - 1, max(0, linenum - 5), -1): ^ ./cpplint/cpplint.py:5503:18: F821 undefined name 'xrange' for linenum in xrange(clean_lines.NumLines()): ^ ./cpplint/cpplint.py:5639:21: F821 undefined name 'xrange' for start_line in xrange(linenum, min(linenum + 3, clean_lines.NumLines())): ^ ./cpplint/cpplint.py:5654:12: F821 undefined name 'xrange' for i in xrange(end_line, min(end_line + 3, clean_lines.NumLines())): ^ ./cpplint/cpplint.py:5911:15: F821 undefined name 'xrange' for line in xrange(clean_lines.NumLines()): ^ ``` --- cpplint/cpplint.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpplint/cpplint.py b/cpplint/cpplint.py index 53dbe81..d6a819b 100755 --- a/cpplint/cpplint.py +++ b/cpplint/cpplint.py @@ -52,6 +52,11 @@ import string import sys import unicodedata +try: + xrange +except NameError: + xrange = range + _USAGE = """ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...] From d98652e03b749ceb533695d7092ad8418668295c Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 12 Mar 2018 18:14:26 +0100 Subject: [PATCH 2/3] Update cpplint.py --- cpplint/cpplint.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpplint/cpplint.py b/cpplint/cpplint.py index d6a819b..8e07cab 100755 --- a/cpplint/cpplint.py +++ b/cpplint/cpplint.py @@ -53,9 +53,9 @@ import sys import unicodedata try: - xrange + xrange # Python 2 except NameError: - xrange = range + xrange = range # Python 3 _USAGE = """ From 099f059086b4250aa0d2546ea3115aae95597ffd Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 12 Mar 2018 18:19:10 +0100 Subject: [PATCH 3/3] cpplint_unittest.py: Define xrange for Python 3 --- cpplint/cpplint_unittest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpplint/cpplint_unittest.py b/cpplint/cpplint_unittest.py index 50d1d82..b3c7725 100755 --- a/cpplint/cpplint_unittest.py +++ b/cpplint/cpplint_unittest.py @@ -43,6 +43,11 @@ import unittest 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