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

Method _else_match

src/black/trans.py:2054–2078  ·  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 ternary expression requirements listed in the 'Requirements' section of this classes' docstring. OR

(LL: list[Leaf])

Source from the content-addressed store, hash-verified

2052
2053 @staticmethod
2054 def _else_match(LL: list[Leaf]) -> int | None:
2055 """
2056 Returns:
2057 string_idx such that @LL[string_idx] is equal to our target (i.e.
2058 matched) string, if this line matches the ternary expression
2059 requirements listed in the 'Requirements' section of this classes'
2060 docstring.
2061 OR
2062 None, otherwise.
2063 """
2064 # If this line is a part of a ternary expression and the first leaf
2065 # contains the "else" keyword...
2066 if (
2067 parent_type(LL[0]) == syms.test
2068 and LL[0].type == token.NAME
2069 and LL[0].value == "else"
2070 ):
2071 is_valid_index = is_valid_index_factory(LL)
2072
2073 idx = 2 if is_valid_index(1) and is_empty_par(LL[1]) else 1
2074 # The next visible leaf MUST contain a string...
2075 if is_valid_index(idx) and LL[idx].type == token.STRING:
2076 return idx
2077
2078 return None
2079
2080 @staticmethod
2081 def _assert_match(LL: list[Leaf]) -> int | None:

Callers 1

do_splitter_matchMethod · 0.95

Calls 4

parent_typeFunction · 0.90
is_empty_parFunction · 0.90
is_valid_index_factoryFunction · 0.85
is_valid_indexFunction · 0.85

Tested by

no test coverage detected