MCPcopy Index your code
hub / github.com/RustPython/RustPython / _iterencode_list

Function _iterencode_list

Lib/json/encoder.py:280–337  ·  view source on GitHub ↗
(lst, _current_indent_level)

Source from the content-addressed store, hash-verified

278 ):
279
280 def _iterencode_list(lst, _current_indent_level):
281 if not lst:
282 yield '[]'
283 return
284 if markers is not None:
285 markerid = id(lst)
286 if markerid in markers:
287 raise ValueError("Circular reference detected")
288 markers[markerid] = lst
289 buf = '['
290 if _indent is not None:
291 _current_indent_level += 1
292 newline_indent = '\n' + _indent * _current_indent_level
293 separator = _item_separator + newline_indent
294 buf += newline_indent
295 else:
296 newline_indent = None
297 separator = _item_separator
298 for i, value in enumerate(lst):
299 if i:
300 buf = separator
301 try:
302 if isinstance(value, str):
303 yield buf + _encoder(value)
304 elif value is None:
305 yield buf + 'null'
306 elif value is True:
307 yield buf + 'true'
308 elif value is False:
309 yield buf + 'false'
310 elif isinstance(value, int):
311 # Subclasses of int/float may override __repr__, but we still
312 # want to encode them as integers/floats in JSON. One example
313 # within the standard library is IntEnum.
314 yield buf + _intstr(value)
315 elif isinstance(value, float):
316 # see comment above for int
317 yield buf + _floatstr(value)
318 else:
319 yield buf
320 if isinstance(value, (list, tuple)):
321 chunks = _iterencode_list(value, _current_indent_level)
322 elif isinstance(value, dict):
323 chunks = _iterencode_dict(value, _current_indent_level)
324 else:
325 chunks = _iterencode(value, _current_indent_level)
326 yield from chunks
327 except GeneratorExit:
328 raise
329 except BaseException as exc:
330 exc.add_note(f'when serializing {type(lst).__name__} item {i}')
331 raise
332 if newline_indent is not None:
333 _current_indent_level -= 1
334 yield '\n' + _indent * _current_indent_level
335 yield ']'
336 if markers is not None:
337 del markers[markerid]

Callers 2

_iterencode_dictFunction · 0.85
_iterencodeFunction · 0.85

Calls 6

idFunction · 0.85
enumerateFunction · 0.85
isinstanceFunction · 0.85
_iterencode_dictFunction · 0.85
_iterencodeFunction · 0.85
add_noteMethod · 0.80

Tested by

no test coverage detected