mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
Include with
statements in complexity calculation (#3771)
This commit is contained in:
parent
bfecf684ce
commit
81de3a16bc
1 changed files with 16 additions and 0 deletions
|
@ -79,6 +79,9 @@ fn get_complexity_number(stmts: &[Stmt]) -> usize {
|
|||
complexity += get_complexity_number(body);
|
||||
complexity += get_complexity_number(orelse);
|
||||
}
|
||||
StmtKind::With { body, .. } | StmtKind::AsyncWith { body, .. } => {
|
||||
complexity += get_complexity_number(body);
|
||||
}
|
||||
StmtKind::While { body, orelse, .. } => {
|
||||
complexity += 1;
|
||||
complexity += get_complexity_number(body);
|
||||
|
@ -403,6 +406,19 @@ def process_detect_lines():
|
|||
finally:
|
||||
if res:
|
||||
errors.append(f"Non-zero exit code {res}")
|
||||
"#;
|
||||
let stmts = parser::parse_program(source, "<filename>")?;
|
||||
assert_eq!(get_complexity_number(&stmts), 2);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with() -> Result<()> {
|
||||
let source = r#"
|
||||
def with_lock():
|
||||
with lock:
|
||||
if foo:
|
||||
print('bar')
|
||||
"#;
|
||||
let stmts = parser::parse_program(source, "<filename>")?;
|
||||
assert_eq!(get_complexity_number(&stmts), 2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue