calculate __getitem__ in terms of an iterable query object that also has a slice() method.
(iterable_query: Query[Any], item: Any)
| 2141 | |
| 2142 | |
| 2143 | def _getitem(iterable_query: Query[Any], item: Any) -> Any: |
| 2144 | """calculate __getitem__ in terms of an iterable query object |
| 2145 | that also has a slice() method. |
| 2146 | |
| 2147 | """ |
| 2148 | |
| 2149 | def _no_negative_indexes(): |
| 2150 | raise IndexError( |
| 2151 | "negative indexes are not accepted by SQL " |
| 2152 | "index / slice operators" |
| 2153 | ) |
| 2154 | |
| 2155 | if isinstance(item, slice): |
| 2156 | start, stop, step = util.decode_slice(item) |
| 2157 | |
| 2158 | if ( |
| 2159 | isinstance(stop, int) |
| 2160 | and isinstance(start, int) |
| 2161 | and stop - start <= 0 |
| 2162 | ): |
| 2163 | return [] |
| 2164 | |
| 2165 | elif (isinstance(start, int) and start < 0) or ( |
| 2166 | isinstance(stop, int) and stop < 0 |
| 2167 | ): |
| 2168 | _no_negative_indexes() |
| 2169 | |
| 2170 | res = iterable_query.slice(start, stop) |
| 2171 | if step is not None: |
| 2172 | return list(res)[None : None : item.step] |
| 2173 | else: |
| 2174 | return list(res) |
| 2175 | else: |
| 2176 | if item == -1: |
| 2177 | _no_negative_indexes() |
| 2178 | else: |
| 2179 | return list(iterable_query[item : item + 1])[0] |
| 2180 | |
| 2181 | |
| 2182 | def _is_mapped_annotation( |
nothing calls this directly
no test coverage detected