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

Function _line_tokens

IPython/core/inputtransformer.py:292–305  ·  view source on GitHub ↗

Helper for has_comment and ends_in_comment_or_string.

(line)

Source from the content-addressed store, hash-verified

290_MULTILINE_STRUCTURE = object()
291
292def _line_tokens(line):
293 """Helper for has_comment and ends_in_comment_or_string."""
294 readline = StringIO(line).readline
295 toktypes = set()
296 try:
297 for t in generate_tokens(readline):
298 toktypes.add(t[0])
299 except TokenError as e:
300 # There are only two cases where a TokenError is raised.
301 if 'multi-line string' in e.args[0]:
302 toktypes.add(_MULTILINE_STRING)
303 else:
304 toktypes.add(_MULTILINE_STRUCTURE)
305 return toktypes
306
307def has_comment(src):
308 """Indicate whether an input line has (i.e. ends in, or is) a comment.

Callers 2

has_commentFunction · 0.85

Calls 2

generate_tokensFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected