From f63d50e3911fadcf8fbd7077324f7bbc62512529 Mon Sep 17 00:00:00 2001 From: Zanie Date: Fri, 28 Jul 2023 16:03:46 -0500 Subject: [PATCH 1/3] Add formatting of type alias statements --- .../fixtures/ruff/statement/type_alias.py | 52 ++++- .../src/statement/stmt_type_alias.rs | 30 ++- ...compatibility@py_312__type_aliases.py.snap | 50 ----- .../format@statement__type_alias.py.snap | 202 +++++++++++++++--- 4 files changed, 253 insertions(+), 81 deletions(-) delete mode 100644 crates/ruff_python_formatter/tests/snapshots/black_compatibility@py_312__type_aliases.py.snap diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/type_alias.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/type_alias.py index 69f3cdafd5068..bc69d09c26adf 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/type_alias.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/type_alias.py @@ -1,4 +1,4 @@ -# Copied from https://github.com/RustPython/Parser/blob/704eb40108239a8faf9bd1d4217e8dad0ac7edb3/parser/src/parser.rs#L901-L936 +# basic usage type X = int type X = int | str @@ -10,6 +10,17 @@ type X[T: int, *Ts, **P] = (T, Ts, P) type X[T: (int, str), *Ts, **P] = (T, Ts, P) +# long name +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = int +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[A] = int +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[Aaaaaaaaaaaaaaaaaaaaaaaaaaaa] = int +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[Aaaaaaaaaaaaaaaaaaaaaaaaaaaa, Bbbbbbbbbbbbb] = int +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = Tttttttttttttttttttttttttttttttttttttttttttttttttttttttt + +# long value +type X = Ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt +type X = Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | Bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | Ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc + # soft keyword as alias name type type = int type match = int @@ -36,3 +47,42 @@ [T] = T type X[T] \ = T + +# type leading comment +type X = ( + # value leading comment + int # value trailing comment +) # type trailing comment + + +# type leading comment +type X = ( + # value leading comment + int # value trailing comment + + # another value trailing comment +) + +# type parameters +type type_params_single_line[aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc] = int +type type_params_arguments_on_their_own_line[aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccc, ddddddddddddd, eeeeeee] = int +type type_params_argument_per_line[aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc, ddddddddddddd, eeeeeeeeeeeeeeee, ffffffffffff] = int +type type_params_trailing_comma[a, b,] = int +type type_params_comments[ + # leading comment + A, + + # in between comment + + B, + # another leading comment + C, + D, # trailing comment +] = int +type type_params_all_kinds[type_var, *type_var_tuple, **param_spec] = int + +# type variable bounds +type bounds_single_line[T: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc)] = T +type bounds_arguments_on_their_own_line[T: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccc, ddddddddddddd, eeeeeee)] = T +type bounds_argument_per_line[T: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc, ddddddddddddd, eeeeeeeeeeeeeeee, ffffffffffff)] = T +type bounds_trailing_comma[T: (a, b,)] = T diff --git a/crates/ruff_python_formatter/src/statement/stmt_type_alias.rs b/crates/ruff_python_formatter/src/statement/stmt_type_alias.rs index d731ed2de4ff7..76e2528e54328 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_type_alias.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_type_alias.rs @@ -1,4 +1,8 @@ -use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter}; +use crate::expression::maybe_parenthesize_expression; +use crate::expression::parentheses::Parenthesize; +use crate::AsFormat; +use crate::{FormatNodeRule, PyFormatter}; +use ruff_formatter::prelude::{space, text}; use ruff_formatter::{write, Buffer, FormatResult}; use ruff_python_ast::StmtTypeAlias; @@ -6,12 +10,28 @@ use ruff_python_ast::StmtTypeAlias; pub struct FormatStmtTypeAlias; impl FormatNodeRule for FormatStmtTypeAlias { - fn fmt_fields(&self, _item: &StmtTypeAlias, f: &mut PyFormatter) -> FormatResult<()> { + fn fmt_fields(&self, item: &StmtTypeAlias, f: &mut PyFormatter) -> FormatResult<()> { + let StmtTypeAlias { + name, + type_params, + value, + range: _, + } = item; + + write!(f, [text("type"), space(), name.as_ref().format()])?; + + if let Some(type_params) = type_params { + write!(f, [type_params.format()])?; + } + write!( f, - [not_yet_implemented_custom_text( - "type NOT_YET_IMPLEMENTED_type_alias = int" - )] + [ + space(), + text("="), + space(), + maybe_parenthesize_expression(value, item, Parenthesize::IfBreaks) + ] ) } } diff --git a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@py_312__type_aliases.py.snap b/crates/ruff_python_formatter/tests/snapshots/black_compatibility@py_312__type_aliases.py.snap deleted file mode 100644 index eaf6dc14e9aca..0000000000000 --- a/crates/ruff_python_formatter/tests/snapshots/black_compatibility@py_312__type_aliases.py.snap +++ /dev/null @@ -1,50 +0,0 @@ ---- -source: crates/ruff_python_formatter/tests/fixtures.rs -input_file: crates/ruff_python_formatter/resources/test/fixtures/black/py_312/type_aliases.py ---- -## Input - -```py -type A=int -type Gen[T]=list[T] - -type = aliased -print(type(42)) -``` - -## Black Differences - -```diff ---- Black -+++ Ruff -@@ -1,5 +1,5 @@ --type A = int --type Gen[T] = list[T] -+type NOT_YET_IMPLEMENTED_type_alias = int -+type NOT_YET_IMPLEMENTED_type_alias = int - - type = aliased - print(type(42)) -``` - -## Ruff Output - -```py -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int - -type = aliased -print(type(42)) -``` - -## Black Output - -```py -type A = int -type Gen[T] = list[T] - -type = aliased -print(type(42)) -``` - - diff --git a/crates/ruff_python_formatter/tests/snapshots/format@statement__type_alias.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__type_alias.py.snap index 163c14fdda258..529a5a6c8c9a3 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@statement__type_alias.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__type_alias.py.snap @@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/ --- ## Input ```py -# Copied from https://github.com/RustPython/Parser/blob/704eb40108239a8faf9bd1d4217e8dad0ac7edb3/parser/src/parser.rs#L901-L936 +# basic usage type X = int type X = int | str @@ -16,6 +16,17 @@ type X[T, *Ts, **P] = (T, Ts, P) type X[T: int, *Ts, **P] = (T, Ts, P) type X[T: (int, str), *Ts, **P] = (T, Ts, P) +# long name +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = int +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[A] = int +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[Aaaaaaaaaaaaaaaaaaaaaaaaaaaa] = int +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[Aaaaaaaaaaaaaaaaaaaaaaaaaaaa, Bbbbbbbbbbbbb] = int +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = Tttttttttttttttttttttttttttttttttttttttttttttttttttttttt + +# long value +type X = Ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt +type X = Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | Bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | Ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc + # soft keyword as alias name type type = int type match = int @@ -42,40 +53,181 @@ type X \ [T] = T type X[T] \ = T + +# type leading comment +type X = ( + # value leading comment + int # value trailing comment +) # type trailing comment + + +# type leading comment +type X = ( + # value leading comment + int # value trailing comment + + # another value trailing comment +) + +# type parameters +type type_params_single_line[aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc] = int +type type_params_arguments_on_their_own_line[aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccc, ddddddddddddd, eeeeeee] = int +type type_params_argument_per_line[aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc, ddddddddddddd, eeeeeeeeeeeeeeee, ffffffffffff] = int +type type_params_trailing_comma[a, b,] = int +type type_params_comments[ + # leading comment + A, + + # in between comment + + B, + # another leading comment + C, + D, # trailing comment +] = int +type type_params_all_kinds[type_var, *type_var_tuple, **param_spec] = int + +# type variable bounds +type bounds_single_line[T: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc)] = T +type bounds_arguments_on_their_own_line[T: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccc, ddddddddddddd, eeeeeee)] = T +type bounds_argument_per_line[T: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc, ddddddddddddd, eeeeeeeeeeeeeeee, ffffffffffff)] = T +type bounds_trailing_comma[T: (a, b,)] = T ``` ## Output ```py -# Copied from https://github.com/RustPython/Parser/blob/704eb40108239a8faf9bd1d4217e8dad0ac7edb3/parser/src/parser.rs#L901-L936 - -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int # recursive -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int +# basic usage + +type X = int +type X = int | str +type X = int | "ForwardRefY" +type X[T] = T | list[X[T]] # recursive +type X[T] = int +type X[T] = list[T] | set[T] +type X[T, *Ts, **P] = (T, Ts, P) +type X[T: int, *Ts, **P] = (T, Ts, P) +type X[T: (int, str), *Ts, **P] = (T, Ts, P) + +# long name +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = int +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[ + A +] = int +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[ + Aaaaaaaaaaaaaaaaaaaaaaaaaaaa +] = int +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx[ + Aaaaaaaaaaaaaaaaaaaaaaaaaaaa, + Bbbbbbbbbbbbb, +] = int +type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = Tttttttttttttttttttttttttttttttttttttttttttttttttttttttt + +# long value +type X = Ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt +type X = ( + Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | Bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + | Ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc +) # soft keyword as alias name -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int +type type = int +type match = int +type case = int # soft keyword as value -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int +type foo = type +type foo = match +type foo = case # multine definitions -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int -type NOT_YET_IMPLEMENTED_type_alias = int +type X = int +type X = int +type X = int +type X = int +type X[T] = T +type X[T] = T +type X[T] = T + +# type leading comment +type X = ( + # value leading comment + int # value trailing comment +) # type trailing comment + + +# type leading comment +type X = ( + # value leading comment + int # value trailing comment + # another value trailing comment +) + +# type parameters +type type_params_single_line[ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbb, + ccccccccccccccccc, +] = int +type type_params_arguments_on_their_own_line[ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbb, + ccccccccccc, + ddddddddddddd, + eeeeeee, +] = int +type type_params_argument_per_line[ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbb, + ccccccccccccccccc, + ddddddddddddd, + eeeeeeeeeeeeeeee, + ffffffffffff, +] = int +type type_params_trailing_comma[ + a, + b, +] = int +type type_params_comments[ + # leading comment + A, + # in between comment + B, + # another leading comment + C, + D, # trailing comment +] = int +type type_params_all_kinds[type_var, *type_var_tuple, **param_spec] = int + +# type variable bounds +type bounds_single_line[ + T: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc) +] = T +type bounds_arguments_on_their_own_line[ + T: ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbb, + ccccccccccc, + ddddddddddddd, + eeeeeee, + ) +] = T +type bounds_argument_per_line[ + T: ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbb, + ccccccccccccccccc, + ddddddddddddd, + eeeeeeeeeeeeeeee, + ffffffffffff, + ) +] = T +type bounds_trailing_comma[ + T: ( + a, + b, + ) +] = T ``` From 08120a0e992d6e5e48f27c5f2a6f6c6534614f48 Mon Sep 17 00:00:00 2001 From: Zanie Date: Wed, 2 Aug 2023 11:11:47 -0500 Subject: [PATCH 2/3] Allow `not_yet_implemented_custom_text` to be unused --- crates/ruff_python_formatter/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ruff_python_formatter/src/lib.rs b/crates/ruff_python_formatter/src/lib.rs index 7813c5d485e48..390798bfc0dad 100644 --- a/crates/ruff_python_formatter/src/lib.rs +++ b/crates/ruff_python_formatter/src/lib.rs @@ -188,6 +188,7 @@ impl Format> for NotYetImplemented { pub(crate) struct NotYetImplementedCustomText(&'static str); /// Formats a placeholder for nodes that have not yet been implemented +#[allow(dead_code)] pub(crate) const fn not_yet_implemented_custom_text( text: &'static str, ) -> NotYetImplementedCustomText { From 465255285275f63872ec7b6389248d10372cf6f3 Mon Sep 17 00:00:00 2001 From: Zanie Date: Wed, 2 Aug 2023 11:15:01 -0500 Subject: [PATCH 3/3] Add leading / trailing bracket / parent tests --- .../fixtures/ruff/statement/type_alias.py | 10 ++++++---- .../format@statement__type_alias.py.snap | 20 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/type_alias.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/type_alias.py index bc69d09c26adf..c50a35a0440e3 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/type_alias.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/type_alias.py @@ -49,9 +49,10 @@ = T # type leading comment -type X = ( +type X = ( # trailing open paren comment # value leading comment int # value trailing comment + # leading close paren comment ) # type trailing comment @@ -60,7 +61,7 @@ # value leading comment int # value trailing comment - # another value trailing comment + # leading close paren comment ) # type parameters @@ -68,7 +69,7 @@ type type_params_arguments_on_their_own_line[aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccc, ddddddddddddd, eeeeeee] = int type type_params_argument_per_line[aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc, ddddddddddddd, eeeeeeeeeeeeeeee, ffffffffffff] = int type type_params_trailing_comma[a, b,] = int -type type_params_comments[ +type type_params_comments[ # trailing open bracket comment # leading comment A, @@ -78,7 +79,8 @@ # another leading comment C, D, # trailing comment -] = int + # leading close bracket comment +] = int # trailing value comment type type_params_all_kinds[type_var, *type_var_tuple, **param_spec] = int # type variable bounds diff --git a/crates/ruff_python_formatter/tests/snapshots/format@statement__type_alias.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@statement__type_alias.py.snap index 529a5a6c8c9a3..1009367aa6170 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@statement__type_alias.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@statement__type_alias.py.snap @@ -55,9 +55,10 @@ type X[T] \ = T # type leading comment -type X = ( +type X = ( # trailing open paren comment # value leading comment int # value trailing comment + # leading close paren comment ) # type trailing comment @@ -66,7 +67,7 @@ type X = ( # value leading comment int # value trailing comment - # another value trailing comment + # leading close paren comment ) # type parameters @@ -74,7 +75,7 @@ type type_params_single_line[aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccc type type_params_arguments_on_their_own_line[aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccc, ddddddddddddd, eeeeeee] = int type type_params_argument_per_line[aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc, ddddddddddddd, eeeeeeeeeeeeeeee, ffffffffffff] = int type type_params_trailing_comma[a, b,] = int -type type_params_comments[ +type type_params_comments[ # trailing open bracket comment # leading comment A, @@ -84,7 +85,8 @@ type type_params_comments[ # another leading comment C, D, # trailing comment -] = int + # leading close bracket comment +] = int # trailing value comment type type_params_all_kinds[type_var, *type_var_tuple, **param_spec] = int # type variable bounds @@ -150,9 +152,10 @@ type X[T] = T type X[T] = T # type leading comment -type X = ( +type X = ( # trailing open paren comment # value leading comment int # value trailing comment + # leading close paren comment ) # type trailing comment @@ -160,7 +163,7 @@ type X = ( type X = ( # value leading comment int # value trailing comment - # another value trailing comment + # leading close paren comment ) # type parameters @@ -188,7 +191,7 @@ type type_params_trailing_comma[ a, b, ] = int -type type_params_comments[ +type type_params_comments[ # trailing open bracket comment # leading comment A, # in between comment @@ -196,7 +199,8 @@ type type_params_comments[ # another leading comment C, D, # trailing comment -] = int + # leading close bracket comment +] = int # trailing value comment type type_params_all_kinds[type_var, *type_var_tuple, **param_spec] = int # type variable bounds