Handles ``Model.objects[:N]`` — the first ``N`` rows of the result set. Negative ``stop`` would mean "everything except the last ``|N|`` rows", which needs a ``COUNT(*)`` to resolve, so it is rejected. Examples:: [:5] → SliceBounds(limit=5, offset=0, reverse=False)
(stop: int)
| 185 | |
| 186 | |
| 187 | def _slice_head(stop: int) -> SliceBounds: |
| 188 | """ |
| 189 | Handles ``Model.objects[:N]`` — the first ``N`` rows of the result set. |
| 190 | Negative ``stop`` would mean "everything except the last ``|N|`` rows", |
| 191 | which needs a ``COUNT(*)`` to resolve, so it is rejected. |
| 192 | |
| 193 | Examples:: |
| 194 | |
| 195 | [:5] → SliceBounds(limit=5, offset=0, reverse=False) |
| 196 | [:0] → SliceBounds(limit=0, offset=0, reverse=False) |
| 197 | [:-2] → raises QueryDefinitionError |
| 198 | |
| 199 | :param stop: upper bound from the slice |
| 200 | :type stop: int |
| 201 | :return: ``SliceBounds(limit=stop, offset=0, reverse=False)`` |
| 202 | :rtype: SliceBounds |
| 203 | """ |
| 204 | if stop < 0: |
| 205 | raise QueryDefinitionError( |
| 206 | "Negative slice stop without a start requires an explicit count; " |
| 207 | "use .count() with .offset()/.limit() instead." |
| 208 | ) |
| 209 | return SliceBounds(limit=stop, offset=0, reverse=False) |
| 210 | |
| 211 | |
| 212 | def _slice_tail(start: int) -> SliceBounds: |
no test coverage detected