@@ -164,7 +164,7 @@ def make_comment(content: str, mode: Mode) -> str:
164164 return "#"
165165
166166 # Preserve comments with fmt directives exactly as-is
167- if content .startswith ("#" ) and _contains_fmt_directive (content ):
167+ if content .startswith ("#" ) and contains_fmt_directive (content ):
168168 return content
169169
170170 if content [0 ] == "#" :
@@ -205,8 +205,8 @@ def _should_process_fmt_comment(
205205
206206 Returns (should_process, is_fmt_off, is_fmt_skip).
207207 """
208- is_fmt_off = _contains_fmt_directive (comment .value , FMT_OFF )
209- is_fmt_skip = _contains_fmt_directive (comment .value , FMT_SKIP )
208+ is_fmt_off = contains_fmt_directive (comment .value , FMT_OFF )
209+ is_fmt_skip = contains_fmt_directive (comment .value , FMT_SKIP )
210210
211211 if not is_fmt_off and not is_fmt_skip :
212212 return False , False , False
@@ -258,9 +258,13 @@ def _handle_comment_only_fmt_block(
258258 fmt_off_idx = None
259259 fmt_on_idx = None
260260 for idx , c in enumerate (all_comments ):
261- if fmt_off_idx is None and c .value in FMT_OFF :
261+ if fmt_off_idx is None and contains_fmt_directive ( c .value , FMT_OFF ) :
262262 fmt_off_idx = idx
263- if fmt_off_idx is not None and idx > fmt_off_idx and c .value in FMT_ON :
263+ if (
264+ fmt_off_idx is not None
265+ and idx > fmt_off_idx
266+ and contains_fmt_directive (c .value , FMT_ON )
267+ ):
264268 fmt_on_idx = idx
265269 break
266270
@@ -401,7 +405,7 @@ def _handle_regular_fmt_block(
401405 parent = first .parent
402406 prefix = first .prefix
403407
404- if comment .value in FMT_OFF :
408+ if contains_fmt_directive ( comment .value , FMT_OFF ) :
405409 first .prefix = prefix [comment .consumed :]
406410 if is_fmt_skip :
407411 first .prefix = ""
@@ -412,7 +416,7 @@ def _handle_regular_fmt_block(
412416 hidden_value = "" .join (str (n ) for n in ignored_nodes )
413417 comment_lineno = leaf .lineno - comment .newlines
414418
415- if comment .value in FMT_OFF :
419+ if contains_fmt_directive ( comment .value , FMT_OFF ) :
416420 fmt_off_prefix = ""
417421 if len (lines ) > 0 and not any (
418422 line [0 ] <= comment_lineno <= line [1 ] for line in lines
@@ -460,7 +464,7 @@ def generate_ignored_nodes(
460464 If comment is skip, returns leaf only.
461465 Stops at the end of the block.
462466 """
463- if _contains_fmt_directive (comment .value , FMT_SKIP ):
467+ if contains_fmt_directive (comment .value , FMT_SKIP ):
464468 yield from _generate_ignored_nodes_from_fmt_skip (leaf , comment , mode )
465469 return
466470 container : LN | None = container_of (leaf )
@@ -717,9 +721,9 @@ def is_fmt_on(container: LN, mode: Mode) -> bool:
717721 """
718722 fmt_on = False
719723 for comment in list_comments (container .prefix , is_endmarker = False , mode = mode ):
720- if comment .value in FMT_ON :
724+ if contains_fmt_directive ( comment .value , FMT_ON ) :
721725 fmt_on = True
722- elif comment .value in FMT_OFF :
726+ elif contains_fmt_directive ( comment .value , FMT_OFF ) :
723727 fmt_on = False
724728 return fmt_on
725729
@@ -748,7 +752,7 @@ def contains_pragma_comment(comment_list: list[Leaf]) -> bool:
748752 return False
749753
750754
751- def _contains_fmt_directive (
755+ def contains_fmt_directive (
752756 comment_line : str , directives : set [str ] = FMT_OFF | FMT_ON | FMT_SKIP
753757) -> bool :
754758 """
0 commit comments