diff --git a/Cargo.lock b/Cargo.lock index 5cc6943..4aed8cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,7 +119,7 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "complexipy" -version = "0.3.0" +version = "0.3.1" dependencies = [ "csv", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index 0f4a7f5..dc7d793 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "complexipy" -version = "0.3.0" +version = "0.3.1" edition = "2021" authors = ["Robin Quintero "] license = "MIT" diff --git a/complexipy/main.py b/complexipy/main.py index 93b88a8..cdedbc6 100644 --- a/complexipy/main.py +++ b/complexipy/main.py @@ -28,7 +28,7 @@ root_dir = Path(__file__).resolve().parent.parent app = typer.Typer(name="complexipy") console = Console() -version = "0.3.0" +version = "0.3.1" @app.command() diff --git a/src/cognitive_complexity/mod.rs b/src/cognitive_complexity/mod.rs index b860024..4045ca0 100644 --- a/src/cognitive_complexity/mod.rs +++ b/src/cognitive_complexity/mod.rs @@ -271,7 +271,12 @@ fn statement_cognitive_complexity(statement: Stmt, nesting_level: u64) -> PyResu } } Stmt::Assign(a) => { - complexity += count_bool_ops(*a.value); + match *a.value { + ast::Expr::IfExp(..) => { + complexity += count_bool_ops(*a.value); + } + _ => {} + } if complexity > 0 { complexity += nesting_level; diff --git a/src/cognitive_complexity/utils.rs b/src/cognitive_complexity/utils.rs index 5f26f2e..14645e3 100644 --- a/src/cognitive_complexity/utils.rs +++ b/src/cognitive_complexity/utils.rs @@ -134,16 +134,13 @@ pub fn count_bool_ops(expr: ast::Expr) -> u64 { let mut complexity: u64 = 0; match expr { - ast::Expr::BoolOp(..) => { + ast::Expr::BoolOp(b) => { complexity += 1; - } - ast::Expr::BinOp(b) => { - complexity += 1; - complexity += count_bool_ops(*b.left); - complexity += count_bool_ops(*b.right); + for value in b.values.iter() { + complexity += count_bool_ops(value.clone()); + } } ast::Expr::UnaryOp(u) => { - complexity += 1; complexity += count_bool_ops(*u.operand); } ast::Expr::Compare(c) => {