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

Method _assign_match

src/black/trans.py:2116–2160  ·  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 assignment statement requirements listed in the 'Requirements' section of this classes' docstring. OR

(LL: list[Leaf])

Source from the content-addressed store, hash-verified

2114
2115 @staticmethod
2116 def _assign_match(LL: list[Leaf]) -> int | None:
2117 """
2118 Returns:
2119 string_idx such that @LL[string_idx] is equal to our target (i.e.
2120 matched) string, if this line matches the assignment statement
2121 requirements listed in the 'Requirements' section of this classes'
2122 docstring.
2123 OR
2124 None, otherwise.
2125 """
2126 # If this line is a part of an expression statement or is a function
2127 # argument AND the first leaf contains a variable name...
2128 if (
2129 parent_type(LL[0]) in [syms.expr_stmt, syms.argument, syms.power]
2130 and LL[0].type == token.NAME
2131 ):
2132 is_valid_index = is_valid_index_factory(LL)
2133
2134 for i, leaf in enumerate(LL):
2135 # We MUST find either an '=' or '+=' symbol...
2136 if leaf.type in [token.EQUAL, token.PLUSEQUAL]:
2137 idx = i + 2 if is_empty_par(LL[i + 1]) else i + 1
2138
2139 # That symbol MUST be followed by a string...
2140 if is_valid_index(idx) and LL[idx].type == token.STRING:
2141 string_idx = idx
2142
2143 # Skip the string trailer, if one exists.
2144 string_parser = StringParser()
2145 idx = string_parser.parse(LL, string_idx)
2146
2147 # The next leaf MAY be a comma iff this line is a part
2148 # of a function argument...
2149 if (
2150 parent_type(LL[0]) == syms.argument
2151 and is_valid_index(idx)
2152 and LL[idx].type == token.COMMA
2153 ):
2154 idx += 1
2155
2156 # But no more leaves are allowed...
2157 if not is_valid_index(idx):
2158 return string_idx
2159
2160 return None
2161
2162 @staticmethod
2163 def _dict_or_lambda_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