Files
llvm-project/lldb/bindings/interface/SBThreadCollectionExtensions.i
Med Ismail Bennani cfc311ed78 [lldb/API] Add __getitem__ subscript support to python SBAPI list class (#181457)
This patch adds __getitem__ method to the SBAPI list classes that were
missing subscript support, enabling Pythonic index access (e.g.,
list[0], list[-1]) in Python bindings.

The implementation adds __getitem__ to the following classes:
- SBStringList
- SBFileSpecList
- SBProcessInfoList
- SBMemoryRegionInfoList
- SBThreadCollection
- SBBreakpointList
- SBModuleSpecList
- SBTypeList

Each implementation follows the same pattern:
- Type validation (raises TypeError for non-integer indices)
- Range validation with negative index support (raises IndexError for
out-of-range)
- Delegates to the appropriate Get*AtIndex() method

The changes are in SWIG interface extension files (.i), implementing the
__getitem__ method in Python bindings while maintaining compatibility
with existing Get*AtIndex() API.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-02-14 04:43:11 +00:00

25 lines
793 B
OpenEdge ABL

%extend lldb::SBThreadCollection {
#ifdef SWIGPYTHON
%pythoncode%{
def __iter__(self):
'''Iterate over all threads in a lldb.SBThreadCollection object.'''
return lldb_iter(self, 'GetSize', 'GetThreadAtIndex')
def __len__(self):
'''Return the number of threads in a lldb.SBThreadCollection object.'''
return self.GetSize()
def __getitem__(self, idx):
'''Get the thread at a given index in an lldb.SBThreadCollection object.'''
if not isinstance(idx, int):
raise TypeError("unsupported index type: %s" % type(idx))
count = len(self)
if not (-count <= idx < count):
raise IndexError("list index out of range")
idx %= count
return self.GetThreadAtIndex(idx)
%}
#endif
}