MCPcopy Create free account
hub / github.com/ipython/ipython / decistmt

Function decistmt

IPython/core/tests/test_inputtransformer.py:457–473  ·  view source on GitHub ↗

Substitute Decimals for floats in a string of statements. Based on an example from the tokenize module docs.

(tokens)

Source from the content-addressed store, hash-verified

455
456@ipt.TokenInputTransformer.wrap
457def decistmt(tokens):
458 """Substitute Decimals for floats in a string of statements.
459
460 Based on an example from the tokenize module docs.
461 """
462 result = []
463 for toknum, tokval, _, _, _ in tokens:
464 if toknum == tokenize.NUMBER and '.' in tokval: # replace NUMBER tokens
465 for newtok in [
466 (tokenize.NAME, 'Decimal'),
467 (tokenize.OP, '('),
468 (tokenize.STRING, repr(tokval)),
469 (tokenize.OP, ')')
470 ]:
471 yield newtok
472 else:
473 yield (toknum, tokval)
474
475
476

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected