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

Method _validate

src/black/trans.py:1133–1174  ·  view source on GitHub ↗

Checks that @line meets all of the requirements listed in this classes' docstring. Refer to `help(BaseStringSplitter)` for a detailed description of those requirements. Returns: * Ok(None), if ALL of the requirements are met. OR

(self, line: Line, string_idx: int)

Source from the content-addressed store, hash-verified

1131 return match_result
1132
1133 def _validate(self, line: Line, string_idx: int) -> TResult[None]:
1134 """
1135 Checks that @line meets all of the requirements listed in this classes'
1136 docstring. Refer to `help(BaseStringSplitter)` for a detailed
1137 description of those requirements.
1138
1139 Returns:
1140 * Ok(None), if ALL of the requirements are met.
1141 OR
1142 * Err(CannotTransform), if ANY of the requirements are NOT met.
1143 """
1144 LL = line.leaves
1145
1146 string_leaf = LL[string_idx]
1147
1148 max_string_length = self._get_max_string_length(line, string_idx)
1149 if len(string_leaf.value) <= max_string_length:
1150 return TErr(
1151 "The string itself is not what is causing this line to be too long."
1152 )
1153
1154 if not string_leaf.parent or [L.type for L in string_leaf.parent.children] == [
1155 token.STRING,
1156 token.NEWLINE,
1157 ]:
1158 return TErr(
1159 f"This string ({string_leaf.value}) appears to be pointless (i.e. has"
1160 " no parent)."
1161 )
1162
1163 if id(line.leaves[string_idx]) in line.comments and contains_pragma_comment(
1164 line.comments[id(line.leaves[string_idx])]
1165 ):
1166 return TErr(
1167 "Line appears to end with an inline pragma comment. Splitting the line"
1168 " could modify the pragma's behavior."
1169 )
1170
1171 if has_triple_quotes(string_leaf.value):
1172 return TErr("We cannot split multiline strings.")
1173
1174 return Ok(None)
1175
1176 def _get_max_string_length(self, line: Line, string_idx: int) -> int:
1177 """

Callers 1

do_matchMethod · 0.95

Calls 5

contains_pragma_commentFunction · 0.90
has_triple_quotesFunction · 0.90
OkClass · 0.90
TErrFunction · 0.85

Tested by

no test coverage detected