This is an archive of the discontinued LLVM Phabricator instance.

[clang/clang-tools-extra] Fix BZ44437 - add_new_check.py does not work with Python 3
ClosedPublic

Authored by kwk on May 5 2020, 7:35 AM.

Details

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:

#!/usr/bin/env 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:

#!/usr/bin/env 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

Diff Detail

Event Timeline

kwk created this revision.May 5 2020, 7:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2020, 7:35 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
kwk edited the summary of this revision. (Show Details)May 5 2020, 7:37 AM
kwk added reviewers: djasper, dsanders.
kwk edited the summary of this revision. (Show Details)
kwk edited the summary of this revision. (Show Details)May 5 2020, 7:39 AM
dsanders accepted this revision.May 5 2020, 1:07 PM

LGTM

This revision is now accepted and ready to land.May 5 2020, 1:07 PM
kwk updated this revision to Diff 262226.May 5 2020, 2:25 PM
This comment was removed by kwk.
This revision was automatically updated to reflect the committed changes.