Skip to content

Commit

Permalink
fix mozilla#3821/Used sum for Boolean(Logging Statements)
Browse files Browse the repository at this point in the history
- Also i found some logging statements that using f string formatting.
  • Loading branch information
StarKBhaviN committed Nov 25, 2023
1 parent 97a0f86 commit 8a07065
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 33 deletions.
4 changes: 2 additions & 2 deletions bugbug/models/annotate_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions bugbug/models/backout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions bugbug/models/defect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
8 changes: 3 additions & 5 deletions bugbug/models/defect_enhancement_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion bugbug/models/fixtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
6 changes: 2 additions & 4 deletions bugbug/models/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions bugbug/models/regressionrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions bugbug/models/regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions bugbug/models/spambug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions bugbug/models/stepstoreproduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 2 additions & 4 deletions bugbug/models/testfailure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions bugbug/models/testselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion scripts/regressor_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8a07065

Please sign in to comment.