From a969e00a73d1220eff37f3f87b3f5bd86ce095cc Mon Sep 17 00:00:00 2001 From: Ranjodh Singh Date: Tue, 8 Apr 2025 02:33:16 +0530 Subject: [PATCH 1/8] Standardize type comments to form `# type: (value)` (psf#2097) Co-authored-by: Pedro Mezacasa Muller --- CHANGES.md | 2 +- docs/the_black_code_style/future_style.md | 2 + src/black/comments.py | 48 ++++++++++++------- src/black/linegen.py | 35 +++++++++----- src/black/lines.py | 8 ++-- src/black/mode.py | 16 +++++++ src/black/nodes.py | 31 +++++++++--- src/black/resources/black.schema.json | 3 +- .../preview_standardize_type_comments.py | 23 +++++++++ 9 files changed, 127 insertions(+), 41 deletions(-) create mode 100644 tests/data/cases/preview_standardize_type_comments.py diff --git a/CHANGES.md b/CHANGES.md index b7520f3f93a..e89f1617a47 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,7 +19,7 @@ ### Preview style - +- Standardize type comments to form `# type: ` (#4645) - Fix a bug where one-liner functions/conditionals marked with `# fmt: skip` would still be formatted (#4552) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index e801874a4f0..11955807fc2 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -29,6 +29,8 @@ Currently, the following features are included in the preview style: - `fix_fmt_skip_in_one_liners`: Fix `# fmt: skip` behaviour on one-liner declarations, such as `def foo(): return "mock" # fmt: skip`, where previously the declaration would have been incorrectly collapsed. +- `standardize_type_comments`: Format type comments which have zero or more spaces between `#` and `type:` or between `type:` and value + to `# type: (value)` (labels/unstable-features)= diff --git a/src/black/comments.py b/src/black/comments.py index 81d3cfd4a35..54d4d5c77a6 100644 --- a/src/black/comments.py +++ b/src/black/comments.py @@ -13,6 +13,7 @@ first_leaf_of, make_simple_prefix, preceding_leaf, + is_type_comment_string, syms, ) from blib2to3.pgen2 import token @@ -50,7 +51,7 @@ class ProtoComment: leading_whitespace: str # leading whitespace before the comment, if any -def generate_comments(leaf: LN) -> Iterator[Leaf]: +def generate_comments(leaf: LN, mode: Mode) -> Iterator[Leaf]: """Clean the prefix of the `leaf` and generate comments from it, if any. Comments in lib2to3 are shoved into the whitespace prefix. This happens @@ -70,7 +71,9 @@ def generate_comments(leaf: LN) -> Iterator[Leaf]: are emitted with a fake STANDALONE_COMMENT token identifier. """ total_consumed = 0 - for pc in list_comments(leaf.prefix, is_endmarker=leaf.type == token.ENDMARKER): + for pc in list_comments( + leaf.prefix, is_endmarker=leaf.type == token.ENDMARKER, mode=mode + ): total_consumed = pc.consumed prefix = make_simple_prefix(pc.newlines, pc.form_feed) yield Leaf(pc.type, pc.value, prefix=prefix) @@ -78,7 +81,7 @@ def generate_comments(leaf: LN) -> Iterator[Leaf]: @lru_cache(maxsize=4096) -def list_comments(prefix: str, *, is_endmarker: bool) -> list[ProtoComment]: +def list_comments(prefix: str, *, is_endmarker: bool, mode: Mode) -> list[ProtoComment]: """Return a list of :class:`ProtoComment` objects parsed from the given `prefix`.""" result: list[ProtoComment] = [] if not prefix or "#" not in prefix: @@ -109,7 +112,7 @@ def list_comments(prefix: str, *, is_endmarker: bool) -> list[ProtoComment]: comment_type = token.COMMENT # simple trailing comment else: comment_type = STANDALONE_COMMENT - comment = make_comment(line) + comment = make_comment(line, mode=mode) result.append( ProtoComment( type=comment_type, @@ -140,7 +143,7 @@ def normalize_trailing_prefix(leaf: LN, total_consumed: int) -> None: leaf.prefix = "" -def make_comment(content: str) -> str: +def make_comment(content: str, mode: Mode) -> str: """Return a consistently formatted comment from the given `content` string. All comments (except for "##", "#!", "#:", '#'") should have a single @@ -158,9 +161,18 @@ def make_comment(content: str) -> str: if ( content and content[0] == NON_BREAKING_SPACE - and not content.lstrip().startswith("type:") + and not is_type_comment_string("# " + content.lstrip(), mode=mode) ): content = " " + content[1:] # Replace NBSP by a simple space + if ( + Preview.standardize_type_comments in mode + and content + and NON_BREAKING_SPACE not in content + and is_type_comment_string("# " + content.lstrip(), mode=mode) + ): + type_part, value_part = content.strip().split(":", 1) + content = type_part.strip() + ": " + value_part.strip() + if content and content[0] not in COMMENT_EXCEPTIONS: content = " " + content return "#" + content @@ -184,7 +196,7 @@ def convert_one_fmt_off_pair( """ for leaf in node.leaves(): previous_consumed = 0 - for comment in list_comments(leaf.prefix, is_endmarker=False): + for comment in list_comments(leaf.prefix, is_endmarker=False, mode=mode): is_fmt_off = comment.value in FMT_OFF is_fmt_skip = _contains_fmt_skip_comment(comment.value, mode) if (not is_fmt_off and not is_fmt_skip) or ( @@ -274,13 +286,13 @@ def generate_ignored_nodes( return container: Optional[LN] = container_of(leaf) while container is not None and container.type != token.ENDMARKER: - if is_fmt_on(container): + if is_fmt_on(container, mode=mode): return # fix for fmt: on in children - if children_contains_fmt_on(container): + if children_contains_fmt_on(container, mode=mode): for index, child in enumerate(container.children): - if isinstance(child, Leaf) and is_fmt_on(child): + if isinstance(child, Leaf) and is_fmt_on(child, mode=mode): if child.type in CLOSING_BRACKETS: # This means `# fmt: on` is placed at a different bracket level # than `# fmt: off`. This is an invalid use, but as a courtesy, @@ -291,12 +303,14 @@ def generate_ignored_nodes( if ( child.type == token.INDENT and index < len(container.children) - 1 - and children_contains_fmt_on(container.children[index + 1]) + and children_contains_fmt_on( + container.children[index + 1], mode=mode + ) ): # This means `# fmt: on` is placed right after an indentation # level, and we shouldn't swallow the previous INDENT token. return - if children_contains_fmt_on(child): + if children_contains_fmt_on(child, mode=mode): return yield child else: @@ -317,7 +331,7 @@ def _generate_ignored_nodes_from_fmt_skip( ignored_nodes: list[LN] = [] # Need to properly format the leaf prefix to compare it to comment.value, # which is also formatted - comments = list_comments(leaf.prefix, is_endmarker=False) + comments = list_comments(leaf.prefix, is_endmarker=False, mode=mode) if not comments or comment.value != comments[0].value: return if prev_sibling is not None: @@ -393,12 +407,12 @@ def _generate_ignored_nodes_from_fmt_skip( yield from iter(ignored_nodes) -def is_fmt_on(container: LN) -> bool: +def is_fmt_on(container: LN, mode: Mode) -> bool: """Determine whether formatting is switched on within a container. Determined by whether the last `# fmt:` comment is `on` or `off`. """ fmt_on = False - for comment in list_comments(container.prefix, is_endmarker=False): + for comment in list_comments(container.prefix, is_endmarker=False, mode=mode): if comment.value in FMT_ON: fmt_on = True elif comment.value in FMT_OFF: @@ -406,11 +420,11 @@ def is_fmt_on(container: LN) -> bool: return fmt_on -def children_contains_fmt_on(container: LN) -> bool: +def children_contains_fmt_on(container: LN, mode: Mode) -> bool: """Determine if children have formatting switched on.""" for child in container.children: leaf = first_leaf_of(child) - if leaf is not None and is_fmt_on(leaf): + if leaf is not None and is_fmt_on(leaf, mode=mode): return True return False diff --git a/src/black/linegen.py b/src/black/linegen.py index 52ef2cf0131..2ccb19c02bc 100644 --- a/src/black/linegen.py +++ b/src/black/linegen.py @@ -139,7 +139,7 @@ def visit_default(self, node: LN) -> Iterator[Line]: """Default `visit_*()` implementation. Recurses to children of `node`.""" if isinstance(node, Leaf): any_open_brackets = self.current_line.bracket_tracker.any_open_brackets() - for comment in generate_comments(node): + for comment in generate_comments(node, mode=self.mode): if any_open_brackets: # any comment within brackets is subject to splitting self.current_line.append(comment) @@ -249,6 +249,7 @@ def visit_dictsetmaker(self, node: Node) -> Iterator[Line]: maybe_make_parens_invisible_in_atom( child, parent=node, + mode=self.mode, remove_brackets_around_comma=False, ) else: @@ -269,6 +270,7 @@ def visit_funcdef(self, node: Node) -> Iterator[Line]: if maybe_make_parens_invisible_in_atom( child, parent=node, + mode=self.mode, remove_brackets_around_comma=False, ): wrap_in_parentheses(node, child, visible=False) @@ -362,7 +364,7 @@ def visit_power(self, node: Node) -> Iterator[Line]: ): wrap_in_parentheses(node, leaf) - remove_await_parens(node) + remove_await_parens(node, mode=self.mode) yield from self.visit_default(node) @@ -409,7 +411,9 @@ def foo(a: int, b: float = 7): ... def foo(a: (int), b: (float) = 7): ... """ assert len(node.children) == 3 - if maybe_make_parens_invisible_in_atom(node.children[2], parent=node): + if maybe_make_parens_invisible_in_atom( + node.children[2], parent=node, mode=self.mode + ): wrap_in_parentheses(node, node.children[2], visible=False) yield from self.visit_default(node) @@ -515,7 +519,9 @@ def visit_atom(self, node: Node) -> Iterator[Line]: first.type == token.LBRACE and last.type == token.RBRACE ): # Lists or sets of one item - maybe_make_parens_invisible_in_atom(node.children[1], parent=node) + maybe_make_parens_invisible_in_atom( + node.children[1], parent=node, mode=self.mode + ) yield from self.visit_default(node) @@ -1381,7 +1387,7 @@ def normalize_invisible_parens( # noqa: C901 Standardizes on visible parentheses for single-element tuples, and keeps existing visible parentheses for other tuples and generator expressions. """ - for pc in list_comments(node.prefix, is_endmarker=False): + for pc in list_comments(node.prefix, is_endmarker=False, mode=mode): if pc.value in FMT_OFF: # This `node` has a prefix with `# fmt: off`, don't mess with parens. return @@ -1433,15 +1439,17 @@ def normalize_invisible_parens( # noqa: C901 if maybe_make_parens_invisible_in_atom( child, parent=node, + mode=mode, remove_brackets_around_comma=True, ): wrap_in_parentheses(node, child, visible=False) elif isinstance(child, Node) and node.type == syms.with_stmt: - remove_with_parens(child, node) + remove_with_parens(child, node, mode=mode) elif child.type == syms.atom: if maybe_make_parens_invisible_in_atom( child, parent=node, + mode=mode, ): wrap_in_parentheses(node, child, visible=False) elif is_one_tuple(child): @@ -1493,7 +1501,7 @@ def _normalize_import_from(parent: Node, child: LN, index: int) -> None: parent.append_child(Leaf(token.RPAR, "")) -def remove_await_parens(node: Node) -> None: +def remove_await_parens(node: Node, mode: Mode) -> None: if node.children[0].type == token.AWAIT and len(node.children) > 1: if ( node.children[1].type == syms.atom @@ -1502,6 +1510,7 @@ def remove_await_parens(node: Node) -> None: if maybe_make_parens_invisible_in_atom( node.children[1], parent=node, + mode=mode, remove_brackets_around_comma=True, ): wrap_in_parentheses(node, node.children[1], visible=False) @@ -1570,7 +1579,7 @@ def _maybe_wrap_cms_in_parens( node.insert_child(1, new_child) -def remove_with_parens(node: Node, parent: Node) -> None: +def remove_with_parens(node: Node, parent: Node, mode: Mode) -> None: """Recursively hide optional parens in `with` statements.""" # Removing all unnecessary parentheses in with statements in one pass is a tad # complex as different variations of bracketed statements result in pretty @@ -1592,21 +1601,23 @@ def remove_with_parens(node: Node, parent: Node) -> None: if maybe_make_parens_invisible_in_atom( node, parent=parent, + mode=mode, remove_brackets_around_comma=True, ): wrap_in_parentheses(parent, node, visible=False) if isinstance(node.children[1], Node): - remove_with_parens(node.children[1], node) + remove_with_parens(node.children[1], node, mode=mode) elif node.type == syms.testlist_gexp: for child in node.children: if isinstance(child, Node): - remove_with_parens(child, node) + remove_with_parens(child, node, mode=mode) elif node.type == syms.asexpr_test and not any( leaf.type == token.COLONEQUAL for leaf in node.leaves() ): if maybe_make_parens_invisible_in_atom( node.children[0], parent=node, + mode=mode, remove_brackets_around_comma=True, ): wrap_in_parentheses(node, node.children[0], visible=False) @@ -1615,6 +1626,7 @@ def remove_with_parens(node: Node, parent: Node) -> None: def maybe_make_parens_invisible_in_atom( node: LN, parent: LN, + mode: Mode, remove_brackets_around_comma: bool = False, ) -> bool: """If it's safe, make the parens in the atom `node` invisible, recursively. @@ -1668,13 +1680,14 @@ def maybe_make_parens_invisible_in_atom( if ( # If the prefix of `middle` includes a type comment with # ignore annotation, then we do not remove the parentheses - not is_type_ignore_comment_string(middle.prefix.strip()) + not is_type_ignore_comment_string(middle.prefix.strip(), mode=mode) ): first.value = "" last.value = "" maybe_make_parens_invisible_in_atom( middle, parent=parent, + mode=mode, remove_brackets_around_comma=remove_brackets_around_comma, ) diff --git a/src/black/lines.py b/src/black/lines.py index 2a719def3c9..8784905332e 100644 --- a/src/black/lines.py +++ b/src/black/lines.py @@ -286,9 +286,9 @@ def contains_uncollapsable_type_comments(self) -> bool: comment_seen = False for leaf_id, comments in self.comments.items(): for comment in comments: - if is_type_comment(comment): + if is_type_comment(comment, mode=self.mode): if comment_seen or ( - not is_type_ignore_comment(comment) + not is_type_ignore_comment(comment, mode=self.mode) and leaf_id not in ignored_ids ): return True @@ -325,7 +325,7 @@ def contains_unsplittable_type_ignore(self) -> bool: # line. for node in self.leaves[-2:]: for comment in self.comments.get(id(node), []): - if is_type_ignore_comment(comment): + if is_type_ignore_comment(comment, mode=self.mode): return True return False @@ -400,7 +400,7 @@ def append_comment(self, comment: Leaf) -> bool: and not last_leaf.value and last_leaf.parent and len(list(last_leaf.parent.leaves())) <= 3 - and not is_type_comment(comment) + and not is_type_comment(comment, mode=self.mode) ): # Comments on an optional parens wrapping a single leaf should belong to # the wrapped node except if it's a type comment. Pinning the comment like diff --git a/src/black/mode.py b/src/black/mode.py index 362607efc86..1e27baae383 100644 --- a/src/black/mode.py +++ b/src/black/mode.py @@ -204,6 +204,7 @@ class Preview(Enum): multiline_string_handling = auto() always_one_newline_after_import = auto() fix_fmt_skip_in_one_liners = auto() + standardize_type_comments = auto() UNSTABLE_FEATURES: set[Preview] = { @@ -285,3 +286,18 @@ def get_cache_key(self) -> str: features_and_magics, ] return ".".join(parts) + + def __hash__(self) -> int: + return hash(( + frozenset(self.target_versions), + self.line_length, + self.string_normalization, + self.is_pyi, + self.is_ipynb, + self.skip_source_first_line, + self.magic_trailing_comma, + frozenset(self.python_cell_magics), + self.preview, + self.unstable, + frozenset(self.enabled_features), + )) diff --git a/src/black/nodes.py b/src/black/nodes.py index 665cb15d910..df7c40d5750 100644 --- a/src/black/nodes.py +++ b/src/black/nodes.py @@ -14,7 +14,7 @@ from mypy_extensions import mypyc_attr from black.cache import CACHE_DIR -from black.mode import Mode +from black.mode import Mode, Preview from black.strings import get_string_prefix, has_triple_quotes from blib2to3 import pygram from blib2to3.pgen2 import token @@ -931,27 +931,44 @@ def is_async_stmt_or_funcdef(leaf: Leaf) -> bool: ) -def is_type_comment(leaf: Leaf) -> bool: +def is_type_comment(leaf: Leaf, mode: Mode) -> bool: """Return True if the given leaf is a type comment. This function should only be used for general type comments (excluding ignore annotations, which should use `is_type_ignore_comment`). Note that general type comments are no longer used in modern version of Python, this function may be deprecated in the future.""" t = leaf.type v = leaf.value - return t in {token.COMMENT, STANDALONE_COMMENT} and v.startswith("# type:") + return t in {token.COMMENT, STANDALONE_COMMENT} and is_type_comment_string(v, mode) -def is_type_ignore_comment(leaf: Leaf) -> bool: +def is_type_comment_string(value: str, mode: Mode) -> bool: + if Preview.standardize_type_comments in mode: + is_valid = value.startswith("#") and value[1:].lstrip().startswith("type:") + else: + is_valid = value.startswith("# type:") + return is_valid + + +def is_type_ignore_comment(leaf: Leaf, mode: Mode) -> bool: """Return True if the given leaf is a type comment with ignore annotation.""" t = leaf.type v = leaf.value - return t in {token.COMMENT, STANDALONE_COMMENT} and is_type_ignore_comment_string(v) + return t in {token.COMMENT, STANDALONE_COMMENT} and is_type_ignore_comment_string( + v, mode + ) -def is_type_ignore_comment_string(value: str) -> bool: +def is_type_ignore_comment_string(value: str, mode: Mode) -> bool: """Return True if the given string match with type comment with ignore annotation.""" - return value.startswith("# type: ignore") + if Preview.standardize_type_comments in mode: + is_valid = is_type_comment_string(value, mode) and value.split(":", 1)[ + 1 + ].lstrip().startswith("ignore") + else: + is_valid = value.startswith("# type: ignore") + + return is_valid def wrap_in_parentheses(parent: Node, child: LN, *, visible: bool = True) -> None: diff --git a/src/black/resources/black.schema.json b/src/black/resources/black.schema.json index 572e5bbfa1e..9a34d284ac9 100644 --- a/src/black/resources/black.schema.json +++ b/src/black/resources/black.schema.json @@ -84,7 +84,8 @@ "wrap_long_dict_values_in_parens", "multiline_string_handling", "always_one_newline_after_import", - "fix_fmt_skip_in_one_liners" + "fix_fmt_skip_in_one_liners", + "standardize_type_comments" ] }, "description": "Enable specific features included in the `--unstable` style. Requires `--preview`. No compatibility guarantees are provided on the behavior or existence of any unstable features." diff --git a/tests/data/cases/preview_standardize_type_comments.py b/tests/data/cases/preview_standardize_type_comments.py new file mode 100644 index 00000000000..5dc11c7111e --- /dev/null +++ b/tests/data/cases/preview_standardize_type_comments.py @@ -0,0 +1,23 @@ +# flags: --preview +def foo( + a, #type:int + b, #type: str + c, # type: List[int] + d, # type: Dict[int, str] + e, # type: ignore + f, # type : ignore + g, # type : ignore +): + pass + +# output +def foo( + a, # type: int + b, # type: str + c, # type: List[int] + d, # type: Dict[int, str] + e, # type: ignore + f, # type : ignore + g, # type : ignore +): + pass \ No newline at end of file From a3474905d12e09ae5725c209f6106746f141d932 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 21:44:17 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/black/comments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/black/comments.py b/src/black/comments.py index 54d4d5c77a6..edde058e33c 100644 --- a/src/black/comments.py +++ b/src/black/comments.py @@ -11,9 +11,9 @@ WHITESPACE, container_of, first_leaf_of, + is_type_comment_string, make_simple_prefix, preceding_leaf, - is_type_comment_string, syms, ) from blib2to3.pgen2 import token From 4233f1ea61185ff78c8c257500b0c8bf1fe5bbfc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 22 Jul 2025 09:26:03 +0000 Subject: [PATCH 3/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGES.md | 1 + docs/the_black_code_style/future_style.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 817af9bf67d..df391744d77 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,7 @@ ### Preview style + - Fix a bug where one-liner functions/conditionals marked with `# fmt: skip` would still be formatted (#4552) - Standardize type comments to form `# type: ` (#4645) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index 845e2c7ead7..ba633047fee 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -29,8 +29,8 @@ Currently, the following features are included in the preview style: - `fix_fmt_skip_in_one_liners`: Fix `# fmt: skip` behaviour on one-liner declarations, such as `def foo(): return "mock" # fmt: skip`, where previously the declaration would have been incorrectly collapsed. -- `standardize_type_comments`: Format type comments which have zero or more spaces between `#` and `type:` or between `type:` and value - to `# type: (value)` +- `standardize_type_comments`: Format type comments which have zero or more spaces + between `#` and `type:` or between `type:` and value to `# type: (value)` (labels/unstable-features)= From b7abcd43774514a50e14c609b6584d865c804742 Mon Sep 17 00:00:00 2001 From: Ranjodh Singh Date: Tue, 22 Jul 2025 15:52:52 +0530 Subject: [PATCH 4/8] Change the missed `NON_BREAKING_SPACE` to `"\N{NO-BREAK SPACE}"` per RUF001 (PR #4694); --- src/black/comments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/black/comments.py b/src/black/comments.py index 709d6b06f2f..096b017c5a4 100644 --- a/src/black/comments.py +++ b/src/black/comments.py @@ -166,7 +166,7 @@ def make_comment(content: str, mode: Mode) -> str: if ( Preview.standardize_type_comments in mode and content - and NON_BREAKING_SPACE not in content + and "\N{NO-BREAK SPACE}" not in content and is_type_comment_string("# " + content.lstrip(), mode=mode) ): type_part, value_part = content.strip().split(":", 1) From fcc72346ac13f8e54bbcfcd68e1c139c91a0e059 Mon Sep 17 00:00:00 2001 From: Ranjodh Singh Date: Mon, 28 Jul 2025 11:28:37 +0530 Subject: [PATCH 5/8] Clean up unnecessary strip calls as per review --- src/black/comments.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/black/comments.py b/src/black/comments.py index 096b017c5a4..25c20a8e677 100644 --- a/src/black/comments.py +++ b/src/black/comments.py @@ -167,9 +167,9 @@ def make_comment(content: str, mode: Mode) -> str: Preview.standardize_type_comments in mode and content and "\N{NO-BREAK SPACE}" not in content - and is_type_comment_string("# " + content.lstrip(), mode=mode) + and is_type_comment_string("#" + content, mode=mode) ): - type_part, value_part = content.strip().split(":", 1) + type_part, value_part = content.split(":", 1) content = type_part.strip() + ": " + value_part.strip() if content and content[0] not in COMMENT_EXCEPTIONS: From cb4d8d6603489bb561efadf9dc50b8e4ffb0a956 Mon Sep 17 00:00:00 2001 From: Ranjodh Singh Date: Thu, 11 Sep 2025 16:03:31 +0530 Subject: [PATCH 6/8] Just triggering CI with something trivial --- docs/the_black_code_style/future_style.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index 82791485f2e..75324fc9f88 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -27,7 +27,7 @@ Currently, the following features are included in the preview style: - `wrap_long_dict_values_in_parens`: Add parentheses around long values in dictionaries ([see below](labels/wrap-long-dict-values)) - `fix_fmt_skip_in_one_liners`: Fix `# fmt: skip` behaviour on one-liner declarations, - such as `def foo(): return "mock" # fmt: skip`, where previously the declaration + such as `def foo(): return "mock" # fmt: skip`, where previously the declaration would have been incorrectly collapsed. - `standardize_type_comments`: Format type comments which have zero or more spaces between `#` and `type:` or between `type:` and value to `# type: (value)` From 320033f081e838ec254113321b2ffc695f5c4a2a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Sep 2025 10:37:02 +0000 Subject: [PATCH 7/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/the_black_code_style/future_style.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/the_black_code_style/future_style.md b/docs/the_black_code_style/future_style.md index 75324fc9f88..34a4cef8182 100644 --- a/docs/the_black_code_style/future_style.md +++ b/docs/the_black_code_style/future_style.md @@ -27,8 +27,8 @@ Currently, the following features are included in the preview style: - `wrap_long_dict_values_in_parens`: Add parentheses around long values in dictionaries ([see below](labels/wrap-long-dict-values)) - `fix_fmt_skip_in_one_liners`: Fix `# fmt: skip` behaviour on one-liner declarations, - such as `def foo(): return "mock" # fmt: skip`, where previously the declaration - would have been incorrectly collapsed. + such as `def foo(): return "mock" # fmt: skip`, where previously the declaration would + have been incorrectly collapsed. - `standardize_type_comments`: Format type comments which have zero or more spaces between `#` and `type:` or between `type:` and value to `# type: (value)` - `wrap_comprehension_in`: Wrap the `in` clause of list and dictionary comprehensions From 89f6afec01f76ff823b6e8c914baea834ba71878 Mon Sep 17 00:00:00 2001 From: Ranjodh Singh Date: Sat, 18 Oct 2025 11:03:47 +0530 Subject: [PATCH 8/8] Add the missing newline at the end of the test case --- tests/data/cases/preview_standardize_type_comments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data/cases/preview_standardize_type_comments.py b/tests/data/cases/preview_standardize_type_comments.py index 5dc11c7111e..2ab45533cf9 100644 --- a/tests/data/cases/preview_standardize_type_comments.py +++ b/tests/data/cases/preview_standardize_type_comments.py @@ -20,4 +20,4 @@ def foo( f, # type : ignore g, # type : ignore ): - pass \ No newline at end of file + pass