MCPcopy Index your code
hub / github.com/couchbase/couchbase-python-client / get_at

Method get_at

couchbase/datastructures.py:211–243  ·  view source on GitHub ↗

Retrieves the item at a specific index in the list. Args: index (int): The index to retrieve. Returns: Any: The value of the element at the specified index. Raises: :class:`~couchbase.exceptions.InvalidArgumentException`: If the index is

(self, index: int)

Source from the content-addressed store, hash-verified

209 raise InvalidArgumentException(message=f'Index: {index} is out of range.') from None
210
211 def get_at(self, index: int) -> Any:
212 """Retrieves the item at a specific index in the list.
213
214 Args:
215 index (int): The index to retrieve.
216
217 Returns:
218 Any: The value of the element at the specified index.
219
220 Raises:
221 :class:`~couchbase.exceptions.InvalidArgumentException`: If the index is out of range.
222
223 """
224 op_type = DatastructureOperationType.ListGetAt
225 with ObservableRequestHandler(op_type, self._impl.observability_instruments) as ds_obs_handler:
226 ds_obs_handler.create_kv_span(self._impl._request_builder._collection_dtls.get_details_as_dict())
227 kv_op_type = KeyValueOperationType.LookupIn
228 with ObservableRequestHandler(kv_op_type, self._impl.observability_instruments) as obs_handler:
229 try:
230 op = subdoc_get(f'[{index}]')
231 req, transcoder = self._impl.request_builder.build_lookup_in_request(self._key,
232 (op,),
233 obs_handler,
234 parent_span=ds_obs_handler.wrapped_span) # noqa: E501
235 sdres: LookupInResult = self._execute_op(self._impl.lookup_in,
236 req,
237 obs_handler,
238 ds_obs_handler.wrapped_span,
239 create_type=True,
240 transcoder=transcoder)
241 return sdres.value[0].get('value', None)
242 except PathNotFoundException:
243 raise InvalidArgumentException(message=f'Index: {index} is out of range.') from None
244
245 def remove_at(self, index: int) -> None:
246 """Removes an item at a specific index from the list.

Callers 3

test_listMethod · 0.45
test_kv_ds_listMethod · 0.45
test_kv_ds_listMethod · 0.45

Calls 7

_execute_opMethod · 0.95
get_details_as_dictMethod · 0.80
create_kv_spanMethod · 0.45
getMethod · 0.45

Tested by 3

test_listMethod · 0.36
test_kv_ds_listMethod · 0.36
test_kv_ds_listMethod · 0.36