Pass FormatContext to NeedsParentheses
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary I started working on this because I assumed that I would need access to options inside of `NeedsParantheses` but it then turned out that I won't. Anyway, it kind of felt nice to pass fewer arguments. So I'm gonna put this out here to get your feedback if you prefer this over passing individual fiels. Oh, I sneeked in another change. I renamed `context.contents` to `source`. `contents` is too generic and doesn't tell you anything. <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan It compiles
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::builders::optional_parentheses;
|
||||
use crate::comments::{dangling_comments, CommentLinePosition, Comments};
|
||||
use crate::comments::{dangling_comments, CommentLinePosition};
|
||||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, parenthesized, NeedsParentheses, Parentheses,
|
||||
Parenthesize,
|
||||
@@ -131,10 +131,9 @@ impl NeedsParentheses for ExprTuple {
|
||||
fn needs_parentheses(
|
||||
&self,
|
||||
parenthesize: Parenthesize,
|
||||
source: &str,
|
||||
comments: &Comments,
|
||||
context: &PyFormatContext,
|
||||
) -> Parentheses {
|
||||
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||
match default_expression_needs_parentheses(self.into(), parenthesize, context) {
|
||||
Parentheses::Optional => Parentheses::Never,
|
||||
parentheses => parentheses,
|
||||
}
|
||||
@@ -148,7 +147,7 @@ fn is_parenthesized(
|
||||
f: &mut Formatter<PyFormatContext<'_>>,
|
||||
) -> bool {
|
||||
let parentheses = '(';
|
||||
let first_char = &f.context().contents()[usize::from(tuple_range.start())..]
|
||||
let first_char = &f.context().source()[usize::from(tuple_range.start())..]
|
||||
.chars()
|
||||
.next();
|
||||
let Some(first_char) = first_char else {
|
||||
|
||||
Reference in New Issue
Block a user