Skip to content

Commit 1dda979

Browse files
Yield instead
1 parent 1a0039a commit 1dda979

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

Lib/tokenize.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def _get_token_colors(syntax, tokenize):
532532
})
533533

534534

535-
def _print_tokens(tokens, *, color=False, exact=False):
535+
def _format_tokens(tokens, *, color=False, exact=False):
536536
theme = _colorize.get_theme(force_no_color=not color)
537537
s = theme.syntax
538538
t = theme.tokenize
@@ -550,7 +550,7 @@ def _print_tokens(tokens, *, color=False, exact=False):
550550
token_color = token_colors.get(token_type, s.reset)
551551
token_name = tok_name[token_type]
552552
visible_range = f"{token.start[0]},{token.start[1]}-{token.end[0]},{token.end[1]}:"
553-
print(
553+
yield (
554554
f"{token_range}{' ' * (20 - len(visible_range))}"
555555
f"{token_color}{token_name:<15}"
556556
f"{s.reset}{token.string!r:<15}"
@@ -597,7 +597,8 @@ def error(message, filename=None, location=None):
597597

598598

599599
# Output the tokenization
600-
_print_tokens(tokens, color=True, exact=args.exact)
600+
for line in _format_tokens(tokens, color=True, exact=args.exact):
601+
print(line)
601602
except IndentationError as err:
602603
line, column = err.args[1][1:3]
603604
error(err.args[0], filename, (line, column))

0 commit comments

Comments
 (0)