If a funcdef has a magic trailing comma in the return type, then we should first split the line with rhs to respect the comma.
(line: Line, mode: Mode)
| 836 | |
| 837 | |
| 838 | def should_split_funcdef_with_rhs(line: Line, mode: Mode) -> bool: |
| 839 | """If a funcdef has a magic trailing comma in the return type, then we should first |
| 840 | split the line with rhs to respect the comma. |
| 841 | """ |
| 842 | return_type_leaves: list[Leaf] = [] |
| 843 | in_return_type = False |
| 844 | |
| 845 | for leaf in line.leaves: |
| 846 | if leaf.type == token.COLON: |
| 847 | in_return_type = False |
| 848 | if in_return_type: |
| 849 | return_type_leaves.append(leaf) |
| 850 | if leaf.type == token.RARROW: |
| 851 | in_return_type = True |
| 852 | |
| 853 | # using `bracket_split_build_line` will mess with whitespace, so we duplicate a |
| 854 | # couple lines from it. |
| 855 | result = Line(mode=line.mode, depth=line.depth) |
| 856 | leaves_to_track = get_leaves_inside_matching_brackets(return_type_leaves) |
| 857 | for leaf in return_type_leaves: |
| 858 | result.append( |
| 859 | leaf, |
| 860 | preformatted=True, |
| 861 | track_bracket=id(leaf) in leaves_to_track, |
| 862 | ) |
| 863 | |
| 864 | # we could also return true if the line is too long, and the return type is longer |
| 865 | # than the param list. Or if `should_split_rhs` returns True. |
| 866 | return result.magic_trailing_comma is not None |
| 867 | |
| 868 | |
| 869 | class _BracketSplitComponent(Enum): |
no test coverage detected
searching dependent graphs…