Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/bindings/python/clang/cindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3853,6 +3853,8 @@ def cursor(self):
cursor._tu = self._tu

conf.lib.clang_annotateTokens(self._tu, byref(self), 1, byref(cursor))
if cursor.is_null():
return None

return cursor

Expand Down
6 changes: 6 additions & 0 deletions clang/bindings/python/tests/cindex/test_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ def test_token_extent(self):

self.assertEqual(extent.start.offset, 4)
self.assertEqual(extent.end.offset, 7)

def test_null_cursor(self):
"""Ensure that the cursor property converts null cursors to None"""
tu = get_tu("int i = 5;")
tokens = list(tu.get_tokens(extent=tu.cursor.extent))
self.assertEqual(tokens[-1].cursor, None)
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Clang Frontend Potentially Breaking Changes

Clang Python Bindings Potentially Breaking Changes
--------------------------------------------------
- Return ``None`` instead of null cursors from ``Token.cursor``
- ``Cursor.from_location`` now returns ``None`` instead of a null cursor.
This eliminates the last known source of null cursors.
- Almost all ``Cursor`` methods now assert that they are called on non-null cursors.
Expand Down
Loading