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

Function _should_auto_indent

Lib/_pyrepl/readline.py:256–273  ·  view source on GitHub ↗
(buffer: list[str], pos: int)

Source from the content-addressed store, hash-verified

254
255
256def _should_auto_indent(buffer: list[str], pos: int) -> bool:
257 # check if last character before "pos" is a colon, ignoring
258 # whitespaces and comments.
259 last_char = None
260 while pos > 0:
261 pos -= 1
262 if last_char is None:
263 if buffer[pos] not in " \t\n#": # ignore whitespaces and comments
264 last_char = buffer[pos]
265 else:
266 # even if we found a non-whitespace character before
267 # original pos, we keep going back until newline is reached
268 # to make sure we ignore comments
269 if buffer[pos] == "\n":
270 break
271 if buffer[pos] == "#":
272 last_char = None
273 return last_char == ":"
274
275
276class maybe_accept(commands.Command):

Callers 1

doMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…