Encode tuple/frozenset values into a C array. The format of the result is like this: ... <length of the seco
(
self, values: dict[tuple[object, ...], int] | dict[frozenset[object], int]
)
| 143 | return self._encode_collection_values(self.frozenset_literals) |
| 144 | |
| 145 | def _encode_collection_values( |
| 146 | self, values: dict[tuple[object, ...], int] | dict[frozenset[object], int] |
| 147 | ) -> list[str]: |
| 148 | """Encode tuple/frozenset values into a C array. |
| 149 | |
| 150 | The format of the result is like this: |
| 151 | |
| 152 | <number of collections> |
| 153 | <length of the first collection> |
| 154 | <literal index of first item> |
| 155 | ... |
| 156 | <literal index of last item> |
| 157 | <length of the second collection> |
| 158 | ... |
| 159 | """ |
| 160 | value_by_index = {index: value for value, index in values.items()} |
| 161 | result = [] |
| 162 | count = len(values) |
| 163 | result.append(str(count)) |
| 164 | for i in range(count): |
| 165 | value = value_by_index[i] |
| 166 | result.append(str(len(value))) |
| 167 | for item in value: |
| 168 | assert _is_literal_value(item) |
| 169 | index = self.literal_index(item) |
| 170 | result.append(str(index)) |
| 171 | return result |
| 172 | |
| 173 | |
| 174 | def _encode_str_values(values: dict[str, int]) -> list[bytes]: |
no test coverage detected