Should `line` be immediately split with `delimiter_split()` after RHS?
(line: Line, opening_bracket: Leaf)
| 1914 | |
| 1915 | |
| 1916 | def should_split_line(line: Line, opening_bracket: Leaf) -> bool: |
| 1917 | """Should `line` be immediately split with `delimiter_split()` after RHS?""" |
| 1918 | |
| 1919 | if not (opening_bracket.parent and opening_bracket.value in "[{("): |
| 1920 | return False |
| 1921 | |
| 1922 | # We're essentially checking if the body is delimited by commas and there's more |
| 1923 | # than one of them (we're excluding the trailing comma and if the delimiter priority |
| 1924 | # is still commas, that means there's more). |
| 1925 | exclude = set() |
| 1926 | trailing_comma = False |
| 1927 | try: |
| 1928 | last_leaf = line.leaves[-1] |
| 1929 | if last_leaf.type == token.COMMA: |
| 1930 | trailing_comma = True |
| 1931 | exclude.add(id(last_leaf)) |
| 1932 | max_priority = line.bracket_tracker.max_delimiter_priority(exclude=exclude) |
| 1933 | except (IndexError, ValueError): |
| 1934 | return False |
| 1935 | |
| 1936 | return max_priority == COMMA_PRIORITY and ( |
| 1937 | (line.mode.magic_trailing_comma and trailing_comma) |
| 1938 | # always explode imports |
| 1939 | or opening_bracket.parent.type in {syms.atom, syms.import_from} |
| 1940 | ) |
| 1941 | |
| 1942 | |
| 1943 | def generate_trailers_to_omit(line: Line, line_length: int) -> Iterator[set[LeafID]]: |
no test coverage detected