Skip to content

Commit

Permalink
Clippy, restore lib.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jul 11, 2023
1 parent 8151d27 commit b8dff47
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use ruff_python_ast::node::AstNode;
use crate::comments::{trailing_comments, Comments};
use crate::context::NodeLevel;
use crate::expression::parentheses::{
default_expression_needs_parentheses, in_parentheses_only_group, NeedsParentheses, Parentheses,
Parenthesize,
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
use crate::prelude::*;
use crate::FormatNodeRule;
Expand Down
12 changes: 9 additions & 3 deletions crates/ruff_python_formatter/src/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl<'input> MaxOperatorPriorityVisitor<'input> {
}

fn update_max_priority(&mut self, current_priority: OperatorPriority) {
self.update_max_priority_with_count(current_priority, 1)
self.update_max_priority_with_count(current_priority, 1);
}

fn update_max_priority_with_count(&mut self, current_priority: OperatorPriority, count: u32) {
Expand Down Expand Up @@ -288,6 +288,9 @@ impl<'input> MaxOperatorPriorityVisitor<'input> {
self.update_max_priority(OperatorPriority::Comprehension);
return;
}
// It's impossible for a file smaller or equal to 4GB to contain more than 2^32 comparisons
// because each comparison requires a left operand, and `n` `operands` and right sides.
#[allow(clippy::cast_possible_truncation)]
Expr::BoolOp(ast::ExprBoolOp {
range: _,
op: _,
Expand All @@ -308,13 +311,16 @@ impl<'input> MaxOperatorPriorityVisitor<'input> {
self.update_max_priority_with_count(OperatorPriority::Conditional, 2);
}

// It's impossible for a file smaller or equal to 4GB to contain more than 2^32 comparisons
// because each comparison requires a left operand, and `n` `operands` and right sides.
#[allow(clippy::cast_possible_truncation)]
Expr::Compare(ast::ExprCompare {
range: _,
left: _,
ops,
comparators: _,
}) => {
self.update_max_priority_with_count(OperatorPriority::Comparator, ops.len() as u32)
self.update_max_priority_with_count(OperatorPriority::Comparator, ops.len() as u32);
}
Expr::Call(ast::ExprCall {
range: _,
Expand Down Expand Up @@ -349,7 +355,7 @@ impl<'input> MaxOperatorPriorityVisitor<'input> {
attr: _,
ctx: _,
}) => {
if has_parentheses(&value, self.source) {
if has_parentheses(value, self.source) {
self.update_max_priority(OperatorPriority::Attribute);
}
}
Expand Down
11 changes: 5 additions & 6 deletions crates/ruff_python_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,11 @@ if True:
#[test]
fn quick_test() {
let src = r#"
def test3():
if True:
field = (
model._meta.pk if from_field is None else model._meta.get_field(from_field)
)
if [
aaaaaa,
BBBB,ccccccccc,ddddddd,eeeeeeeeee,ffffff
] & bbbbbbbbbbbbbbbbbbddddddddddddddddddddddddddddbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb:
...
"#;
// Tokenize once
let mut tokens = Vec::new();
Expand Down

0 comments on commit b8dff47

Please sign in to comment.