diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/trailing_comments.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/trailing_comments.py index 5bfe148cf5f30..86c33a0f4ed79 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/trailing_comments.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/trailing_comments.py @@ -1,6 +1,29 @@ +# Pragma reserved width fixtures +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # noqa: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # type: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # pyright: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # pylint: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # noqa This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # nocoverage: This should break + + +# Pragma fixtures for non-breaking space (lead by NBSP) +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # noqa: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # type: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # pyright: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # pylint: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # noqa This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # nocoverage: This should break + + # As of adding this fixture Black adds a space before the non-breaking space if part of a type pragma. # https://github.com/psf/black/blob/b4dca26c7d93f930bbd5a7b552807370b60d4298/src/black/comments.py#L122-L129 -i2 = "" #  type: Add space before leading NBSP followed by spaces -i3 = "" #type: A space is added -i4 = "" #  type: Add space before leading NBSP followed by a space -i5 = "" # type: Add space before leading NBSP +i = "" #  type: Add space before leading NBSP followed by spaces +i = "" #type: A space is added +i = "" #  type: Add space before leading NBSP followed by a space +i = "" # type: Add space before leading NBSP +i = "" #  type: Add space before two leading NBSP + + +# A noqa as `#\u{A0}\u{A0}noqa` becomes `# \u{A0}noqa` +i = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" #  noqa diff --git a/crates/ruff_python_formatter/src/comments/format.rs b/crates/ruff_python_formatter/src/comments/format.rs index 62df38c07116a..e682924284d56 100644 --- a/crates/ruff_python_formatter/src/comments/format.rs +++ b/crates/ruff_python_formatter/src/comments/format.rs @@ -357,17 +357,33 @@ impl Format> for FormatTrailingEndOfLineComment<'_> { let normalized_comment = normalize_comment(self.comment, source)?; - // Start with 2 because of the two leading spaces. - let mut reserved_width = 2; - - // SAFE: The formatted file is <= 4GB, and each comment should as well. - #[allow(clippy::cast_possible_truncation)] - for c in normalized_comment.chars() { - reserved_width += match c { - '\t' => f.options().tab_width().value(), - c => c.width().unwrap_or(0) as u32, + // Trim the normalized comment to detect excluded pragmas (strips NBSP). + let trimmed = strip_comment_prefix(&normalized_comment)?.trim_start(); + + let is_pragma = if let Some((maybe_pragma, _)) = trimmed.split_once(':') { + matches!(maybe_pragma, "noqa" | "type" | "pyright" | "pylint") + } else { + trimmed.starts_with("noqa") + }; + + // Don't reserve width for excluded pragma comments. + let reserved_width = if is_pragma { + 0 + } else { + // Start with 2 because of the two leading spaces. + let mut width = 2; + + // SAFETY: The formatted file is <= 4GB, and each comment should as well. + #[allow(clippy::cast_possible_truncation)] + for c in normalized_comment.chars() { + width += match c { + '\t' => f.options().tab_width().value(), + c => c.width().unwrap_or(0) as u32, + } } - } + + width + }; write!( f, @@ -442,11 +458,7 @@ fn normalize_comment<'a>( let trimmed = comment_text.trim_end(); - let Some(content) = trimmed.strip_prefix('#') else { - return Err(FormatError::syntax_error( - "Didn't find expected comment token `#`", - )); - }; + let content = strip_comment_prefix(trimmed)?; if content.is_empty() { return Ok(Cow::Borrowed("#")); @@ -476,6 +488,17 @@ fn normalize_comment<'a>( Ok(Cow::Owned(std::format!("# {}", content.trim_start()))) } +/// A helper for stripping '#' from comments. +fn strip_comment_prefix(comment_text: &str) -> FormatResult<&str> { + let Some(content) = comment_text.strip_prefix('#') else { + return Err(FormatError::syntax_error( + "Didn't find expected comment token `#`", + )); + }; + + Ok(content) +} + /// Format the empty lines between a node and its trailing comments. /// /// For example, given: diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__comments6.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__comments6.py.snap index f48ec014b3d7c..6725d8d840c1f 100644 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__comments6.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__comments6.py.snap @@ -156,7 +156,7 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite ) -@@ -108,11 +112,20 @@ +@@ -108,11 +112,18 @@ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ) @@ -176,10 +176,7 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite + ], # type: ignore ) --aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] -+aaaaaaaaaaaaa, bbbbbbbbb = map( -+ list, map(itertools.chain.from_iterable, zip(*items)) -+) # type: ignore[arg-type] + aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] ``` ## Ruff Output @@ -313,9 +310,7 @@ call_to_some_function_asdf( ], # type: ignore ) -aaaaaaaaaaaaa, bbbbbbbbb = map( - list, map(itertools.chain.from_iterable, zip(*items)) -) # type: ignore[arg-type] +aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] ``` ## Black Output diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__expression.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__expression.py.snap index d8e7464160a18..0ee2ffdceb0bb 100644 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__expression.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__expression.py.snap @@ -300,17 +300,6 @@ last_call() ) # note: no trailing comma pre-3.6 call(*gidgets[:2]) call(a, *gidgets[:2]) -@@ -142,7 +143,9 @@ - xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore - sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) - ) --xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore -+xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[ -+ ..., List[SomeClass] -+] = classmethod( # type: ignore - sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) - ) - xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( ``` ## Ruff Output @@ -461,9 +450,7 @@ very_long_variable_name_filters: t.List[ xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) ) -xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[ - ..., List[SomeClass] -] = classmethod( # type: ignore +xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) ) xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__power_op_spacing.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__power_op_spacing.py.snap deleted file mode 100644 index de37c7048668d..0000000000000 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__power_op_spacing.py.snap +++ /dev/null @@ -1,232 +0,0 @@ ---- -source: crates/ruff_python_formatter/tests/fixtures.rs -input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/power_op_spacing.py ---- -## Input - -```py -def function(**kwargs): - t = a**2 + b**3 - return t ** 2 - - -def function_replace_spaces(**kwargs): - t = a **2 + b** 3 + c ** 4 - - -def function_dont_replace_spaces(): - {**a, **b, **c} - - -a = 5**~4 -b = 5 ** f() -c = -(5**2) -d = 5 ** f["hi"] -e = lazy(lambda **kwargs: 5) -f = f() ** 5 -g = a.b**c.d -h = 5 ** funcs.f() -i = funcs.f() ** 5 -j = super().name ** 5 -k = [(2**idx, value) for idx, value in pairs] -l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001) -m = [([2**63], [1, 2**63])] -n = count <= 10**5 -o = settings(max_examples=10**6) -p = {(k, k**2): v**2 for k, v in pairs} -q = [10**i for i in range(6)] -r = x**y - -a = 5.0**~4.0 -b = 5.0 ** f() -c = -(5.0**2.0) -d = 5.0 ** f["hi"] -e = lazy(lambda **kwargs: 5) -f = f() ** 5.0 -g = a.b**c.d -h = 5.0 ** funcs.f() -i = funcs.f() ** 5.0 -j = super().name ** 5.0 -k = [(2.0**idx, value) for idx, value in pairs] -l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001) -m = [([2.0**63.0], [1.0, 2**63.0])] -n = count <= 10**5.0 -o = settings(max_examples=10**6.0) -p = {(k, k**2): v**2.0 for k, v in pairs} -q = [10.5**i for i in range(6)] - - -# WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873) -if hasattr(view, "sum_of_weights"): - return np.divide( # type: ignore[no-any-return] - view.variance, # type: ignore[union-attr] - view.sum_of_weights, # type: ignore[union-attr] - out=np.full(view.sum_of_weights.shape, np.nan), # type: ignore[union-attr] - where=view.sum_of_weights**2 > view.sum_of_weights_squared, # type: ignore[union-attr] - ) - -return np.divide( - where=view.sum_of_weights_of_weight_long**2 > view.sum_of_weights_squared, # type: ignore -) -``` - -## Black Differences - -```diff ---- Black -+++ Ruff -@@ -55,9 +55,11 @@ - view.variance, # type: ignore[union-attr] - view.sum_of_weights, # type: ignore[union-attr] - out=np.full(view.sum_of_weights.shape, np.nan), # type: ignore[union-attr] -- where=view.sum_of_weights**2 > view.sum_of_weights_squared, # type: ignore[union-attr] -+ where=view.sum_of_weights**2 -+ > view.sum_of_weights_squared, # type: ignore[union-attr] - ) - - return np.divide( -- where=view.sum_of_weights_of_weight_long**2 > view.sum_of_weights_squared, # type: ignore -+ where=view.sum_of_weights_of_weight_long**2 -+ > view.sum_of_weights_squared, # type: ignore - ) -``` - -## Ruff Output - -```py -def function(**kwargs): - t = a**2 + b**3 - return t**2 - - -def function_replace_spaces(**kwargs): - t = a**2 + b**3 + c**4 - - -def function_dont_replace_spaces(): - {**a, **b, **c} - - -a = 5**~4 -b = 5 ** f() -c = -(5**2) -d = 5 ** f["hi"] -e = lazy(lambda **kwargs: 5) -f = f() ** 5 -g = a.b**c.d -h = 5 ** funcs.f() -i = funcs.f() ** 5 -j = super().name ** 5 -k = [(2**idx, value) for idx, value in pairs] -l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001) -m = [([2**63], [1, 2**63])] -n = count <= 10**5 -o = settings(max_examples=10**6) -p = {(k, k**2): v**2 for k, v in pairs} -q = [10**i for i in range(6)] -r = x**y - -a = 5.0**~4.0 -b = 5.0 ** f() -c = -(5.0**2.0) -d = 5.0 ** f["hi"] -e = lazy(lambda **kwargs: 5) -f = f() ** 5.0 -g = a.b**c.d -h = 5.0 ** funcs.f() -i = funcs.f() ** 5.0 -j = super().name ** 5.0 -k = [(2.0**idx, value) for idx, value in pairs] -l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001) -m = [([2.0**63.0], [1.0, 2**63.0])] -n = count <= 10**5.0 -o = settings(max_examples=10**6.0) -p = {(k, k**2): v**2.0 for k, v in pairs} -q = [10.5**i for i in range(6)] - - -# WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873) -if hasattr(view, "sum_of_weights"): - return np.divide( # type: ignore[no-any-return] - view.variance, # type: ignore[union-attr] - view.sum_of_weights, # type: ignore[union-attr] - out=np.full(view.sum_of_weights.shape, np.nan), # type: ignore[union-attr] - where=view.sum_of_weights**2 - > view.sum_of_weights_squared, # type: ignore[union-attr] - ) - -return np.divide( - where=view.sum_of_weights_of_weight_long**2 - > view.sum_of_weights_squared, # type: ignore -) -``` - -## Black Output - -```py -def function(**kwargs): - t = a**2 + b**3 - return t**2 - - -def function_replace_spaces(**kwargs): - t = a**2 + b**3 + c**4 - - -def function_dont_replace_spaces(): - {**a, **b, **c} - - -a = 5**~4 -b = 5 ** f() -c = -(5**2) -d = 5 ** f["hi"] -e = lazy(lambda **kwargs: 5) -f = f() ** 5 -g = a.b**c.d -h = 5 ** funcs.f() -i = funcs.f() ** 5 -j = super().name ** 5 -k = [(2**idx, value) for idx, value in pairs] -l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001) -m = [([2**63], [1, 2**63])] -n = count <= 10**5 -o = settings(max_examples=10**6) -p = {(k, k**2): v**2 for k, v in pairs} -q = [10**i for i in range(6)] -r = x**y - -a = 5.0**~4.0 -b = 5.0 ** f() -c = -(5.0**2.0) -d = 5.0 ** f["hi"] -e = lazy(lambda **kwargs: 5) -f = f() ** 5.0 -g = a.b**c.d -h = 5.0 ** funcs.f() -i = funcs.f() ** 5.0 -j = super().name ** 5.0 -k = [(2.0**idx, value) for idx, value in pairs] -l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001) -m = [([2.0**63.0], [1.0, 2**63.0])] -n = count <= 10**5.0 -o = settings(max_examples=10**6.0) -p = {(k, k**2): v**2.0 for k, v in pairs} -q = [10.5**i for i in range(6)] - - -# WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873) -if hasattr(view, "sum_of_weights"): - return np.divide( # type: ignore[no-any-return] - view.variance, # type: ignore[union-attr] - view.sum_of_weights, # type: ignore[union-attr] - out=np.full(view.sum_of_weights.shape, np.nan), # type: ignore[union-attr] - where=view.sum_of_weights**2 > view.sum_of_weights_squared, # type: ignore[union-attr] - ) - -return np.divide( - where=view.sum_of_weights_of_weight_long**2 > view.sum_of_weights_squared, # type: ignore -) -``` - - diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__torture.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__torture.py.snap index 3a57c5b7a90ff..f44e1053f0b4b 100644 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__torture.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@simple_cases__torture.py.snap @@ -50,17 +50,14 @@ assert ( ) # assert sort_by_dependency( -@@ -25,9 +25,11 @@ +@@ -25,9 +25,9 @@ class A: def foo(self): for _ in range(10): - aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( -- xxxxxxxxxxxx ++ aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( # pylint: disable=no-member + xxxxxxxxxxxx - ) # pylint: disable=no-member -+ aaaaaaaaaaaaaaaaaaa = ( -+ bbbbbbbbbbbbbbb.cccccccccc( # pylint: disable=no-member -+ xxxxxxxxxxxx -+ ) + ) @@ -97,10 +94,8 @@ importA class A: def foo(self): for _ in range(10): - aaaaaaaaaaaaaaaaaaa = ( - bbbbbbbbbbbbbbb.cccccccccc( # pylint: disable=no-member - xxxxxxxxxxxx - ) + aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( # pylint: disable=no-member + xxxxxxxxxxxx ) diff --git a/crates/ruff_python_formatter/tests/snapshots/format@trailing_comments.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@trailing_comments.py.snap index 8ddbd6b6f5e2a..982bb00711926 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@trailing_comments.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@trailing_comments.py.snap @@ -4,22 +4,72 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/trailing_c --- ## Input ```py +# Pragma reserved width fixtures +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # noqa: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # type: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # pyright: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # pylint: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # noqa This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # nocoverage: This should break + + +# Pragma fixtures for non-breaking space (lead by NBSP) +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # noqa: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # type: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # pyright: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # pylint: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # noqa This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # nocoverage: This should break + + # As of adding this fixture Black adds a space before the non-breaking space if part of a type pragma. # https://github.com/psf/black/blob/b4dca26c7d93f930bbd5a7b552807370b60d4298/src/black/comments.py#L122-L129 -i2 = "" #  type: Add space before leading NBSP followed by spaces -i3 = "" #type: A space is added -i4 = "" #  type: Add space before leading NBSP followed by a space -i5 = "" # type: Add space before leading NBSP +i = "" #  type: Add space before leading NBSP followed by spaces +i = "" #type: A space is added +i = "" #  type: Add space before leading NBSP followed by a space +i = "" # type: Add space before leading NBSP +i = "" #  type: Add space before two leading NBSP + + +# A noqa as `#\u{A0}\u{A0}noqa` becomes `# \u{A0}noqa` +i = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" #  noqa ``` ## Output ```py +# Pragma reserved width fixtures +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # noqa: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # type: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # pyright: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # pylint: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # noqa This shouldn't break +i = ( + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", +) # nocoverage: This should break + + +# Pragma fixtures for non-breaking space (lead by NBSP) +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # noqa: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) #  type: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # pyright: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # pylint: This shouldn't break +i = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",) # noqa This shouldn't break +i = ( + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", +) # nocoverage: This should break + + # As of adding this fixture Black adds a space before the non-breaking space if part of a type pragma. # https://github.com/psf/black/blob/b4dca26c7d93f930bbd5a7b552807370b60d4298/src/black/comments.py#L122-L129 -i2 = "" #   type: Add space before leading NBSP followed by spaces -i3 = "" # type: A space is added -i4 = "" #   type: Add space before leading NBSP followed by a space -i5 = "" #  type: Add space before leading NBSP +i = "" #   type: Add space before leading NBSP followed by spaces +i = "" # type: A space is added +i = "" #   type: Add space before leading NBSP followed by a space +i = "" #  type: Add space before leading NBSP +i = "" #  type: Add space before two leading NBSP + + +# A noqa as `#\u{A0}\u{A0}noqa` becomes `# \u{A0}noqa` +i = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # noqa ```