Skip to content

Commit

Permalink
[clang/clang-tools-extra] Fix BZ44437 - add_new_check.py does not wor…
Browse files Browse the repository at this point in the history
…k with Python 3

Summary:
This fixes https://bugs.llvm.org/show_bug.cgi?id=44437.

Thanks to Arnaud Desitter for providing the patch in the bug report!

A simple example program to reproduce this error is this:

```lang=python

import sys

with open(sys.argv[0], 'r') as f:
  lines = f.readlines()
lines = iter(lines)
line = lines.next()
print(line)
```

which will error with this in python python 3:

```
Traceback (most recent call last):
  File "./mytest.py", line 8, in <module>
    line = lines.next()
AttributeError: 'list_iterator' object has no attribute 'next'
```

Here's the same strategy applied to my test program as applied to the `add_new_check.py` file:

```lang=python

import sys

with open(sys.argv[0], 'r') as f:
  lines = f.readlines()
lines = iter(lines)
line = next(lines)
print(line)
```

The built-in function `next()` is new since Python 2.6: https://docs.python.org/2/library/functions.html#next

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79419
  • Loading branch information
kwk committed May 5, 2020
1 parent bf6a26b commit 24b4965
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/add_new_check.py
Expand Up @@ -172,7 +172,7 @@ def adapt_module(module_path, module, check_name, check_name_camel):
lines = iter(lines)
try:
while True:
line = lines.next()
line = next(lines)
if not header_added:
match = re.search('#include "(.*)"', line)
if match:
Expand All @@ -197,7 +197,7 @@ def adapt_module(module_path, module, check_name, check_name_camel):
# If we didn't find the check name on this line, look on the
# next one.
prev_line = line
line = lines.next()
line = next(lines)
match = re.search(' *"([^"]*)"', line)
if match:
current_check_name = match.group(1)
Expand Down

0 comments on commit 24b4965

Please sign in to comment.