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

Method _assert_match

src/black/trans.py:2081–2113  ·  view source on GitHub ↗

Returns: string_idx such that @LL[string_idx] is equal to our target (i.e. matched) string, if this line matches the assert statement requirements listed in the 'Requirements' section of this classes' docstring. OR

(LL: list[Leaf])

Source from the content-addressed store, hash-verified

2079
2080 @staticmethod
2081 def _assert_match(LL: list[Leaf]) -> int | None:
2082 """
2083 Returns:
2084 string_idx such that @LL[string_idx] is equal to our target (i.e.
2085 matched) string, if this line matches the assert statement
2086 requirements listed in the 'Requirements' section of this classes'
2087 docstring.
2088 OR
2089 None, otherwise.
2090 """
2091 # If this line is a part of an assert statement and the first leaf
2092 # contains the "assert" keyword...
2093 if parent_type(LL[0]) == syms.assert_stmt and LL[0].value == "assert":
2094 is_valid_index = is_valid_index_factory(LL)
2095
2096 for i, leaf in enumerate(LL):
2097 # We MUST find a comma...
2098 if leaf.type == token.COMMA:
2099 idx = i + 2 if is_empty_par(LL[i + 1]) else i + 1
2100
2101 # That comma MUST be followed by a string...
2102 if is_valid_index(idx) and LL[idx].type == token.STRING:
2103 string_idx = idx
2104
2105 # Skip the string trailer, if one exists.
2106 string_parser = StringParser()
2107 idx = string_parser.parse(LL, string_idx)
2108
2109 # But no more leaves are allowed...
2110 if not is_valid_index(idx):
2111 return string_idx
2112
2113 return None
2114
2115 @staticmethod
2116 def _assign_match(LL: list[Leaf]) -> int | None:

Callers 1

do_splitter_matchMethod · 0.95

Calls 6

parseMethod · 0.95
parent_typeFunction · 0.90
is_empty_parFunction · 0.90
is_valid_index_factoryFunction · 0.85
is_valid_indexFunction · 0.85
StringParserClass · 0.85

Tested by

no test coverage detected