Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't move type param opening parenthesis comment #8163

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
D, # trailing comment
# leading close bracket comment
] = int # trailing value comment
type type_params_single_comment[ # trailing open bracket comment
A,
B
] = int
type type_params_all_kinds[type_var, *type_var_tuple, **param_spec] = int

# type variable bounds
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff_python_formatter/src/type_param/type_params.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use ruff_formatter::write;
use ruff_formatter::FormatResult;
use ruff_python_ast::AstNode;
use ruff_python_ast::TypeParams;
use ruff_text_size::Ranged;

use crate::builders::PyFormatterExtensions;
use crate::comments::{trailing_comments, SourceComment};
use crate::comments::SourceComment;
use crate::expression::parentheses::parenthesized;
use crate::prelude::*;

Expand All @@ -24,15 +23,16 @@ impl FormatNodeRule<TypeParams> for FormatTypeParams {
// ] = ...
let comments = f.context().comments().clone();
let dangling_comments = comments.dangling(item.as_any_node_ref());
write!(f, [trailing_comments(dangling_comments)])?;

let items = format_with(|f| {
f.join_comma_separated(item.end())
.nodes(item.type_params.iter())
.finish()
});

parenthesized("[", &items, "]").fmt(f)
parenthesized("[", &items, "]")
.with_dangling_comments(dangling_comments)
.fmt(f)
}

fn fmt_dangling_comments(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ f3 = { # f3


# Non-empty parentheses: These are not allowed without a value
def f1[T](): # f1
def f1[ # f1
T
]():
pass


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ type type_params_comments[ # trailing open bracket comment
D, # trailing comment
# leading close bracket comment
] = int # trailing value comment
type type_params_single_comment[ # trailing open bracket comment
A,
B
] = int
type type_params_all_kinds[type_var, *type_var_tuple, **param_spec] = int

# type variable bounds
Expand Down Expand Up @@ -201,6 +205,10 @@ type type_params_comments[ # trailing open bracket comment
D, # trailing comment
# leading close bracket comment
] = int # trailing value comment
type type_params_single_comment[ # trailing open bracket comment
A,
B,
] = int
type type_params_all_kinds[type_var, *type_var_tuple, **param_spec] = int

# type variable bounds
Expand Down
Loading