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

Function is_split_before_delimiter

src/black/brackets.py:233–326  ·  view source on GitHub ↗

Return the priority of the `leaf` delimiter, given a line break before it. The delimiter priorities returned here are from those delimiters that would cause a line break before themselves. Higher numbers are higher priority.

(leaf: Leaf, previous: Leaf | None = None)

Source from the content-addressed store, hash-verified

231
232
233def is_split_before_delimiter(leaf: Leaf, previous: Leaf | None = None) -> Priority:
234 """Return the priority of the `leaf` delimiter, given a line break before it.
235
236 The delimiter priorities returned here are from those delimiters that would
237 cause a line break before themselves.
238
239 Higher numbers are higher priority.
240 """
241 if is_vararg(leaf, within=VARARGS_PARENTS | UNPACKING_PARENTS):
242 # * and ** might also be MATH_OPERATORS but in this case they are not.
243 # Don't treat them as a delimiter.
244 return 0
245
246 if (
247 leaf.type == token.DOT
248 and leaf.parent
249 and leaf.parent.type not in {syms.import_from, syms.dotted_name}
250 and (previous is None or previous.type in CLOSING_BRACKETS)
251 ):
252 return DOT_PRIORITY
253
254 if (
255 leaf.type in MATH_OPERATORS
256 and leaf.parent
257 and leaf.parent.type not in {syms.factor, syms.star_expr}
258 ):
259 return MATH_PRIORITIES[leaf.type]
260
261 if leaf.type in COMPARATORS:
262 return COMPARATOR_PRIORITY
263
264 if (
265 leaf.type == token.STRING
266 and previous is not None
267 and previous.type == token.STRING
268 ):
269 return STRING_PRIORITY
270
271 if leaf.type not in {token.NAME, token.ASYNC}:
272 return 0
273
274 if (
275 leaf.value == "for"
276 and leaf.parent
277 and leaf.parent.type in {syms.comp_for, syms.old_comp_for}
278 or leaf.type == token.ASYNC
279 ):
280 if (
281 not isinstance(leaf.prev_sibling, Leaf)
282 or leaf.prev_sibling.value != "async"
283 ):
284 return COMPREHENSION_PRIORITY
285
286 if (
287 leaf.value == "if"
288 and leaf.parent
289 and leaf.parent.type in {syms.comp_if, syms.old_comp_if}
290 ):

Callers 1

markMethod · 0.85

Calls 1

is_varargFunction · 0.90

Tested by

no test coverage detected