llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Jannick Kremer (DeinAlptraum) <details> <summary>Changes</summary> This partially addresses point 5 from https://github.com/llvm/llvm-project/issues/156680. --- Full diff: https://github.com/llvm/llvm-project/pull/177764.diff 2 Files Affected: - (modified) clang/bindings/python/clang/cindex.py (+18) - (modified) clang/bindings/python/tests/cindex/test_code_completion.py (+1-1) ``````````diff diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 428ac694720fa..a1b716587a5f0 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -3283,8 +3283,26 @@ def from_param(self) -> _Pointer[CCRStructure]: def __del__(self) -> None: conf.lib.clang_disposeCodeCompleteResults(self) + def __len__(self) -> int: + return self.ptr.contents.numResults + + def __getitem__(self, key: int) -> CodeCompletionResult: + if len(self) <= key: + raise IndexError + + return self.ptr.contents.results[key] + @property def results(self) -> CCRStructure: + warnings.warn( + "Access to 'CodeCompletionResult's through " + "'CodeCompletionResults.results' will be removed in a future release." + "Existing uses of 'CodeCompletionResults.results' should be changed " + "to directly use 'CodeCompletionResults': it nows supports '__len__' " + "and '__getitem__', so it can be used the same as " + "'CodeCompletionResults.results'.", + DeprecationWarning, + ) return self.ptr.contents @property diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py b/clang/bindings/python/tests/cindex/test_code_completion.py index c376b0e5cce40..c0a6a7069344b 100644 --- a/clang/bindings/python/tests/cindex/test_code_completion.py +++ b/clang/bindings/python/tests/cindex/test_code_completion.py @@ -14,7 +14,7 @@ def check_completion_results(self, cr, expected): self.assertIsNotNone(cr) self.assertEqual(len(cr.diagnostics), 0) - completions = [str(c) for c in cr.results] + completions = [str(c) for c in cr] for c in expected: self.assertIn(c, completions) `````````` </details> https://github.com/llvm/llvm-project/pull/177764 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
