MCPcopy
hub / github.com/psf/black / line

Method line

src/black/linegen.py:121–144  ·  view source on GitHub ↗

Generate a line. If the line is empty, only emit if it makes sense. If the line is too long, split it first and then generate. If any lines were generated, set up a new current_line.

(self, indent: int = 0)

Source from the content-addressed store, hash-verified

119 self.__post_init__()
120
121 def line(self, indent: int = 0) -> Iterator[Line]:
122 """Generate a line.
123
124 If the line is empty, only emit if it makes sense.
125 If the line is too long, split it first and then generate.
126
127 If any lines were generated, set up a new current_line.
128 """
129 if not self.current_line:
130 self.current_line.depth += indent
131 return # Line is empty, don't emit. Creating a new one unnecessary.
132
133 if len(self.current_line.leaves) == 1 and is_async_stmt_or_funcdef(
134 self.current_line.leaves[0]
135 ):
136 # Special case for async def/for/with statements. `visit_async_stmt`
137 # adds an `ASYNC` leaf then visits the child def/for/with statement
138 # nodes. Line yields from those nodes shouldn't treat the former
139 # `ASYNC` leaf as a complete line.
140 return
141
142 complete_line = self.current_line
143 self.current_line = Line(mode=self.mode, depth=complete_line.depth + indent)
144 yield complete_line
145
146 def visit_default(self, node: LN) -> Iterator[Line]:
147 """Default `visit_*()` implementation. Recurses to children of `node`."""

Callers 12

visit_defaultMethod · 0.95
visit_INDENTMethod · 0.95
visit_DEDENTMethod · 0.95
visit_stmtMethod · 0.95
visit_funcdefMethod · 0.95
visit_match_caseMethod · 0.95
visit_simple_stmtMethod · 0.95
visit_async_stmtMethod · 0.95
visit_decoratorsMethod · 0.95
visit_SEMIMethod · 0.95
visit_ENDMARKERMethod · 0.95

Calls 2

is_async_stmt_or_funcdefFunction · 0.90
LineClass · 0.90

Tested by

no test coverage detected