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

Method compute_bracket_indent

Lib/idlelib/pyparse.py:458–487  ·  view source on GitHub ↗

Return number of spaces the next line should be indented. Line continuation must be C_BRACKET.

(self)

Source from the content-addressed store, hash-verified

456 self.stmt_bracketing = tuple(bracketing)
457
458 def compute_bracket_indent(self):
459 """Return number of spaces the next line should be indented.
460
461 Line continuation must be C_BRACKET.
462 """
463 self._study2()
464 assert self.continuation == C_BRACKET
465 j = self.lastopenbracketpos
466 code = self.code
467 n = len(code)
468 origi = i = code.rfind('\n', 0, j) + 1
469 j = j+1 # one beyond open bracket
470 # find first list item; set i to start of its line
471 while j < n:
472 m = _itemre(code, j)
473 if m:
474 j = m.end() - 1 # index of first interesting char
475 extra = 0
476 break
477 else:
478 # this line is junk; advance to next line
479 i = j = code.find('\n', j) + 1
480 else:
481 # nothing interesting follows the bracket;
482 # reproduce the bracket line's indentation + a level
483 j = i = origi
484 while code[j] in " \t":
485 j = j+1
486 extra = self.indentwidth
487 return len(code[i:j].expandtabs(self.tabwidth)) + extra
488
489 def get_num_lines_in_stmt(self):
490 """Return number of physical lines in last stmt.

Callers 1

Calls 5

_study2Method · 0.95
rfindMethod · 0.45
endMethod · 0.45
findMethod · 0.45
expandtabsMethod · 0.45

Tested by

no test coverage detected