Refactor sum() calls to use boolean values directly (#3852)

This commit is contained in:
StarKBhaviN 2023-11-27 20:40:27 +05:30 коммит произвёл GitHub
Родитель 4094c86d3c
Коммит 20ea1e581b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
16 изменённых файлов: 32 добавлений и 42 удалений

Просмотреть файл

@ -112,12 +112,12 @@ class AnnotateIgnoreModel(CommitModel):
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]

Просмотреть файл

@ -113,11 +113,11 @@ class BackoutModel(CommitModel):
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]

Просмотреть файл

@ -71,11 +71,11 @@ class BrowserNameModel(IssueModel):
logger.info(
"%d issues belong to Firefox",
sum(1 for label in classes.values() if label == 1),
sum(label == 1 for label in classes.values()),
)
logger.info(
"%d issues do not belong to Firefox",
sum(1 for label in classes.values() if label == 0),
sum(label == 0 for label in classes.values()),
)
return classes, [0, 1]

Просмотреть файл

@ -168,11 +168,7 @@ class BugTypeModel(BugModel):
for type_ in TYPE_LIST:
logger.info(
"%d %s bugs",
sum(
1
for target in classes.values()
if target[TYPE_LIST.index(type_)] == 1
),
sum(target[TYPE_LIST.index(type_)] == 1 for target in classes.values()),
type_,
)

Просмотреть файл

@ -258,8 +258,8 @@ class DefectModel(BugModel):
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]

Просмотреть файл

@ -21,14 +21,12 @@ class DefectEnhancementTaskModel(DefectModel):
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"]

Просмотреть файл

@ -111,7 +111,7 @@ class FixTimeModel(BugModel):
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,
)

Просмотреть файл

@ -82,11 +82,11 @@ class NeedsDiagnosisModel(IssueModel):
logger.info(
"%d issues have not been moved to needsdiagnosis",
sum(1 for label in classes.values() if label == 1),
sum(label == 1 for label in classes.values()),
)
logger.info(
"%d issues have been moved to needsdiagnosis",
sum(1 for label in classes.values() if label == 0),
sum(label == 0 for label in classes.values()),
)
return classes, [0, 1]

Просмотреть файл

@ -20,11 +20,9 @@ class RegressionModel(DefectModel):
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]

Просмотреть файл

@ -83,11 +83,11 @@ class RegressionRangeModel(BugModel):
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]

Просмотреть файл

@ -201,12 +201,12 @@ class RegressorModel(CommitModel):
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 @@ class RegressorModel(CommitModel):
# 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)

Просмотреть файл

@ -112,11 +112,11 @@ class SpamBugModel(BugModel):
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]

Просмотреть файл

@ -85,11 +85,11 @@ class StepsToReproduceModel(BugModel):
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]

Просмотреть файл

@ -101,12 +101,10 @@ class TestFailureModel(CommitModel):
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]

Просмотреть файл

@ -540,14 +540,14 @@ class TestSelectModel(Model):
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]

Просмотреть файл

@ -172,7 +172,7 @@ class RegressorFinder(object):
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)