MCPcopy Index your code
hub / github.com/python/cpython / untokenize

Function untokenize

Lib/tokenize.py:326–344  ·  view source on GitHub ↗

Transform tokens back into Python source code. It returns a bytes object, encoded using the ENCODING token, which is the first token sequence output by tokenize. Each element returned by the iterable must be a token sequence with at least two elements, a token number and token value

(iterable)

Source from the content-addressed store, hash-verified

324
325
326def untokenize(iterable):
327 """Transform tokens back into Python source code.
328 It returns a bytes object, encoded using the ENCODING
329 token, which is the first token sequence output by tokenize.
330
331 Each element returned by the iterable must be a token sequence
332 with at least two elements, a token number and token value. If
333 only two tokens are passed, the resulting output is poor.
334
335 The result is guaranteed to tokenize back to match the input so
336 that the conversion is lossless and round-trips are assured.
337 The guarantee applies only to the token type and token string as
338 the spacing between tokens (column positions) may change.
339 """
340 ut = Untokenizer()
341 out = ut.untokenize(iterable)
342 if ut.encoding is not None:
343 out = out.encode(ut.encoding)
344 return out
345
346
347def _get_normal_name(orig_enc):

Callers

nothing calls this directly

Calls 3

untokenizeMethod · 0.95
UntokenizerClass · 0.85
encodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…