MCPcopy Index your code
hub / github.com/python/mypy / _encode_collection_values

Method _encode_collection_values

mypyc/codegen/literals.py:145–171  ·  view source on GitHub ↗

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]
    )

Source from the content-addressed store, hash-verified

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
174def _encode_str_values(values: dict[str, int]) -> list[bytes]:

Callers 2

encoded_tuple_valuesMethod · 0.95

Calls 7

literal_indexMethod · 0.95
lenFunction · 0.85
strClass · 0.85
rangeClass · 0.85
_is_literal_valueFunction · 0.85
appendMethod · 0.80
itemsMethod · 0.45

Tested by

no test coverage detected