From 8a070650ff583b0ff4acf6d2766ca4ec041ccc92 Mon Sep 17 00:00:00 2001 From: Bhavin Date: Sat, 25 Nov 2023 09:28:38 +0530 Subject: [PATCH] fix #3821/Used sum for Boolean(Logging Statements) - Also i found some logging statements that using f string formatting. --- bugbug/models/annotate_ignore.py | 4 ++-- bugbug/models/backout.py | 4 ++-- bugbug/models/defect.py | 4 ++-- bugbug/models/defect_enhancement_task.py | 8 +++----- bugbug/models/fixtime.py | 2 +- bugbug/models/regression.py | 6 ++---- bugbug/models/regressionrange.py | 4 ++-- bugbug/models/regressor.py | 6 +++--- bugbug/models/spambug.py | 4 ++-- bugbug/models/stepstoreproduce.py | 4 ++-- bugbug/models/testfailure.py | 6 ++---- bugbug/models/testselect.py | 6 +++--- scripts/regressor_finder.py | 2 +- 13 files changed, 27 insertions(+), 33 deletions(-) diff --git a/bugbug/models/annotate_ignore.py b/bugbug/models/annotate_ignore.py index b5b5095f9c..5df3e3658c 100644 --- a/bugbug/models/annotate_ignore.py +++ b/bugbug/models/annotate_ignore.py @@ -112,12 +112,12 @@ def get_labels(self): logger.info( "%d commits that can be ignored", - sum(1 for label in classes.values() if label == 1), + sum(label == 1 for label in classes.values()), ) logger.info( "%d commits that cannot be ignored", - sum(1 for label in classes.values() if label == 0), + sum(label == 0 for label in classes.values()), ) return classes, [0, 1] diff --git a/bugbug/models/backout.py b/bugbug/models/backout.py index 00faf0f9a8..e6100d9676 100644 --- a/bugbug/models/backout.py +++ b/bugbug/models/backout.py @@ -113,11 +113,11 @@ def get_labels(self): logger.info( "%d commits were backed out", - sum(1 for label in classes.values() if label == 1), + sum(label == 1 for label in classes.values()), ) logger.info( "%d commits were not backed out", - sum(1 for label in classes.values() if label == 0), + sum(label == 0 for label in classes.values()), ) return classes, [0, 1] diff --git a/bugbug/models/defect.py b/bugbug/models/defect.py index d6b6436430..2cd5aef90f 100644 --- a/bugbug/models/defect.py +++ b/bugbug/models/defect.py @@ -258,8 +258,8 @@ def _has_type_changed(bug): def get_labels(self) -> tuple[dict[int, Any], list[Any]]: classes = self.get_bugbug_labels("bug") - logger.info("%d bugs", (sum(1 for label in classes.values() if label == 1))) - logger.info("%d non-bugs", (sum(1 for label in classes.values() if label == 0))) + logger.info("%d bugs", (sum(label == 1 for label in classes.values()))) + logger.info("%d non-bugs", (sum(label == 0 for label in classes.values()))) return classes, [0, 1] diff --git a/bugbug/models/defect_enhancement_task.py b/bugbug/models/defect_enhancement_task.py index 74718a2938..81b8e5dbca 100644 --- a/bugbug/models/defect_enhancement_task.py +++ b/bugbug/models/defect_enhancement_task.py @@ -21,14 +21,12 @@ def __init__(self, lemmatization=False, historical=False): def get_labels(self) -> tuple[dict[int, Any], list[Any]]: classes = self.get_bugbug_labels("defect_enhancement_task") - logger.info( - "%d defects", sum(1 for label in classes.values() if label == "defect") - ) + logger.info("%d defects", sum(label == "defect" for label in classes.values())) logger.info( "%d enhancements", - sum(1 for label in classes.values() if label == "enhancement"), + sum(label == "enhancement" for label in classes.values()), ) - logger.info("%d tasks", sum(1 for label in classes.values() if label == "task")) + logger.info("%d tasks", sum(label == "task" for label in classes.values())) return classes, ["defect", "enhancement", "task"] diff --git a/bugbug/models/fixtime.py b/bugbug/models/fixtime.py index 5cfda0ca78..89919f8678 100644 --- a/bugbug/models/fixtime.py +++ b/bugbug/models/fixtime.py @@ -111,7 +111,7 @@ def _quantiles(n): for i in range(len(quantiles) + 1): logger.info( "%d bugs are in the %dth quantile", - sum(1 for label in classes.values() if label == i), + sum(label == i for label in classes.values()), i, ) diff --git a/bugbug/models/regression.py b/bugbug/models/regression.py index 11bc22eb4c..d0798209a9 100644 --- a/bugbug/models/regression.py +++ b/bugbug/models/regression.py @@ -20,11 +20,9 @@ def __init__(self, lemmatization=False, historical=False): def get_labels(self) -> tuple[dict[int, Any], list[int]]: classes = self.get_bugbug_labels("regression") + logger.info("%d regression bugs", sum(label == 1 for label in classes.values())) logger.info( - "%d regression bugs", sum(1 for label in classes.values() if label == 1) - ) - logger.info( - "%d non-regression bugs", sum(1 for label in classes.values() if label == 0) + "%d non-regression bugs", sum(label == 0 for label in classes.values()) ) return classes, [0, 1] diff --git a/bugbug/models/regressionrange.py b/bugbug/models/regressionrange.py index 91bde02afc..58a2af5169 100644 --- a/bugbug/models/regressionrange.py +++ b/bugbug/models/regressionrange.py @@ -83,11 +83,11 @@ def get_labels(self): classes[bug_id] = 0 logger.info( "%d bugs have regression range", - sum(1 for label in classes.values() if label == 1), + sum(label == 1 for label in classes.values()), ) logger.info( "%d bugs don't have a regression range", - sum(1 for label in classes.values() if label == 0), + sum(label == 0 for label in classes.values()), ) return classes, [0, 1] diff --git a/bugbug/models/regressor.py b/bugbug/models/regressor.py index 72729c4f96..1dce121a3f 100644 --- a/bugbug/models/regressor.py +++ b/bugbug/models/regressor.py @@ -201,12 +201,12 @@ def get_labels(self): logger.info( "%d commits caused regressions", - sum(1 for label in classes.values() if label == 1), + sum(label == 1 for label in classes.values()), ) logger.info( "%d commits did not cause regressions", - sum(1 for label in classes.values() if label == 0), + sum(label == 0 for label in classes.values()), ) return classes, [0, 1] @@ -275,7 +275,7 @@ def evaluation(self) -> None: # Step 1. Calculate % of patches which cause regressions. total_landings = len(results) - total_regressions = sum(1 for _, is_reg in results if is_reg) + total_regressions = sum(is_reg for _, is_reg in results) average_regression_rate = total_regressions / total_landings logger.info("Average risk is %d", average_regression_rate) diff --git a/bugbug/models/spambug.py b/bugbug/models/spambug.py index e09a93c92a..332f1e13a1 100644 --- a/bugbug/models/spambug.py +++ b/bugbug/models/spambug.py @@ -112,11 +112,11 @@ def get_labels(self): logger.info( "%d bugs are classified as non-spam", - sum(1 for label in classes.values() if label == 0), + sum(label == 0 for label in classes.values()), ) logger.info( "%d bugs are classified as spam", - sum(1 for label in classes.values() if label == 1), + sum(label == 1 for label in classes.values()), ) return classes, [0, 1] diff --git a/bugbug/models/stepstoreproduce.py b/bugbug/models/stepstoreproduce.py index 582fba33eb..76947527ad 100644 --- a/bugbug/models/stepstoreproduce.py +++ b/bugbug/models/stepstoreproduce.py @@ -85,11 +85,11 @@ def get_labels(self): logger.info( "%d bugs have no steps to reproduce", - sum(1 for label in classes.values() if label == 0), + sum(label == 0 for label in classes.values()), ) logger.info( "%d bugs have steps to reproduce", - sum(1 for label in classes.values() if label == 1), + sum(label == 1 for label in classes.values()), ) return classes, [0, 1] diff --git a/bugbug/models/testfailure.py b/bugbug/models/testfailure.py index 9ddaa0090f..04e5af4cda 100644 --- a/bugbug/models/testfailure.py +++ b/bugbug/models/testfailure.py @@ -101,12 +101,10 @@ def get_labels(self): else: classes[rev] = 0 - logger.info( - "%d commits failed", sum(1 for label in classes.values() if label == 1) - ) + logger.info("%d commits failed", sum(label == 1 for label in classes.values())) logger.info( "%d commits did not fail", - sum(1 for label in classes.values() if label == 0), + sum(label == 0 for label in classes.values()), ) return classes, [0, 1] diff --git a/bugbug/models/testselect.py b/bugbug/models/testselect.py index caf8105776..684b1b495e 100644 --- a/bugbug/models/testselect.py +++ b/bugbug/models/testselect.py @@ -540,14 +540,14 @@ def get_labels(self): logger.info("%d pushes considered", len(pushes)) logger.info( "%d pushes with at least one failure", - sum(1 for push in pushes if len(push["failures"]) > 0), + sum(len(push["failures"]) > 0 for push in pushes), ) logger.info( - "%d push/jobs failed", sum(1 for label in classes.values() if label == 1) + "%d push/jobs failed", sum(label == 1 for label in classes.values()) ) logger.info( "%d push/jobs did not fail", - sum(1 for label in classes.values() if label == 0), + sum(label == 0 for label in classes.values()), ) return classes, [0, 1] diff --git a/scripts/regressor_finder.py b/scripts/regressor_finder.py index 302eabc913..c5e5a432e0 100644 --- a/scripts/regressor_finder.py +++ b/scripts/regressor_finder.py @@ -172,7 +172,7 @@ def get_commits_to_ignore(self) -> None: logger.info( "...of which %d are backed-out", - sum(1 for commit in commits_to_ignore if commit["type"] == "backedout"), + sum(commit["type"] == "backedout" for commit in commits_to_ignore), ) db.write(IGNORED_COMMITS_DB, commits_to_ignore)