Parenthesize numbers during attribute accesses (#3189)

This commit is contained in:
Charlie Marsh 2023-02-23 14:57:23 -05:00 committed by GitHub
parent 32d165b7ad
commit bda2a0007a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 153 deletions

View file

@ -22,6 +22,9 @@ pub mod shared_traits;
pub mod trivia;
pub fn fmt(contents: &str) -> Result<Formatted<ASTFormatContext>> {
// Create a reusable locator.
let locator = Locator::new(contents);
// Tokenize once.
let tokens: Vec<LexResult> = ruff_rustpython::tokenize(contents);
@ -37,7 +40,7 @@ pub fn fmt(contents: &str) -> Result<Formatted<ASTFormatContext>> {
// Attach trivia.
attach(&mut python_cst, trivia);
normalize_newlines(&mut python_cst);
normalize_parentheses(&mut python_cst);
normalize_parentheses(&mut python_cst, &locator);
format!(
ASTFormatContext::new(
@ -45,7 +48,7 @@ pub fn fmt(contents: &str) -> Result<Formatted<ASTFormatContext>> {
indent_style: IndentStyle::Space(4),
line_width: 88.try_into().unwrap(),
},
Locator::new(contents)
locator,
),
[format::builders::block(&python_cst)]
)