Checks if the given comment contains format directives, alone or paired with other comments. Defaults to checking all directives (skip, off, on, yapf), but can be narrowed to specific ones. Matching styles: # foobar <-- single comment # foobar #
(
comment_line: str, directives: set[str] = FMT_OFF | FMT_ON | FMT_SKIP
)
| 838 | |
| 839 | |
| 840 | def contains_fmt_directive( |
| 841 | comment_line: str, directives: set[str] = FMT_OFF | FMT_ON | FMT_SKIP |
| 842 | ) -> bool: |
| 843 | """ |
| 844 | Checks if the given comment contains format directives, alone or paired with |
| 845 | other comments. |
| 846 | |
| 847 | Defaults to checking all directives (skip, off, on, yapf), but can be |
| 848 | narrowed to specific ones. |
| 849 | |
| 850 | Matching styles: |
| 851 | # foobar <-- single comment |
| 852 | # foobar # foobar # foobar <-- multiple comments |
| 853 | # foobar; foobar <-- list of comments (; separated) |
| 854 | """ |
| 855 | semantic_comment_blocks = [ |
| 856 | comment_line, |
| 857 | *[ |
| 858 | _COMMENT_PREFIX + comment.strip() |
| 859 | for comment in comment_line.split(_COMMENT_PREFIX)[1:] |
| 860 | ], |
| 861 | *[ |
| 862 | _COMMENT_PREFIX + comment.strip() |
| 863 | for comment in comment_line.strip(_COMMENT_PREFIX).split( |
| 864 | _COMMENT_LIST_SEPARATOR |
| 865 | ) |
| 866 | ], |
| 867 | ] |
| 868 | |
| 869 | return any(comment in directives for comment in semantic_comment_blocks) |
no outgoing calls
no test coverage detected