Skip to content

Commit

Permalink
Fix pyqt5_to_pqt6 script when src_to_tokens returns duplicate tokens
Browse files Browse the repository at this point in the history
Sometimes src_to_tokens returns multiple tokens at the same offset.
This is likely a bug in some versions of tokenize_rt, but this
workaround avoids an exception occurring in the QGIS script.
  • Loading branch information
nyalldawson authored and troopa81 committed May 16, 2024
1 parent a278540 commit d2a173f
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions scripts/pyqt5_to_pyqt6/pyqt5_to_pyqt6.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ def visit_import(_node: ast.ImportFrom, _parent):
for i, token in reversed_enumerate(tokens):
if token.offset in import_offsets:
end_import_offset = Offset(*import_offsets[token.offset][-2:])
del import_offsets[token.offset]
assert tokens[i].src == 'from'
token_index = i + 1
while not tokens[token_index].src.strip():
Expand Down

0 comments on commit d2a173f

Please sign in to comment.