MCPcopy Index your code
hub / github.com/ormar-orm/ormar / _reverse_range

Function _reverse_range

ormar/queryset/utils.py:290–312  ·  view source on GitHub ↗

Handles ``[-A:-B]`` (both bounds negative). Out-of-order bounds (``start >= stop``, e.g. ``[-2:-5]``) clamp to empty; otherwise the slice is emulated by flipping the ORDER BY, offsetting ``|stop|`` rows from the end, and limiting to ``|start| - |stop|`` rows. Examples::

(start: int, stop: int)

Source from the content-addressed store, hash-verified

288
289
290def _reverse_range(start: int, stop: int) -> SliceBounds:
291 """
292 Handles ``[-A:-B]`` (both bounds negative). Out-of-order bounds
293 (``start >= stop``, e.g. ``[-2:-5]``) clamp to empty; otherwise the
294 slice is emulated by flipping the ORDER BY, offsetting ``|stop|`` rows
295 from the end, and limiting to ``|start| - |stop|`` rows.
296
297 Examples::
298
299 [-5:-2] → SliceBounds(limit=3, offset=2, reverse=True)
300 [-3:-1] → SliceBounds(limit=2, offset=1, reverse=True)
301 [-2:-5] → SliceBounds(limit=0, offset=0, reverse=True) # empty
302
303 :param start: negative lower bound
304 :type start: int
305 :param stop: negative upper bound
306 :type stop: int
307 :return: ``SliceBounds(..., reverse=True)``
308 :rtype: SliceBounds
309 """
310 if start >= stop:
311 return SliceBounds(limit=0, offset=0, reverse=True)
312 return SliceBounds(limit=stop - start, offset=-stop, reverse=True)
313
314
315def translate_list_to_dict( # noqa: CCR001

Callers 1

_slice_rangeFunction · 0.85

Calls 1

SliceBoundsClass · 0.85

Tested by

no test coverage detected