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

Function contains_fmt_directive

src/black/comments.py:840–869  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

838
839
840def 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)

Callers 8

make_commentFunction · 0.85
generate_ignored_nodesFunction · 0.85
is_fmt_onFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected