Skip to content

Commit aa9f1b2

Browse files
authored
Further improvements to typing conformance script (#22596)
1 parent f9dd973 commit aa9f1b2

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

.github/workflows/typing_conformance.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,10 @@ jobs:
9696
--output ../typing_conformance_diagnostics.diff
9797
)
9898
99-
echo "${CONFORMANCE_SUITE_COMMIT}" > conformance-suite-commit
100-
10199
# NOTE: astral-sh-bot uses this artifact to post comments on PRs.
102100
# Make sure to update the bot if you rename the artifact.
103101
- name: Upload diff
104102
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
105103
with:
106104
name: typing_conformance_diagnostics_diff
107105
path: typing_conformance_diagnostics.diff
108-
109-
# NOTE: astral-sh-bot uses this artifact to post comments on PRs.
110-
# Make sure to update the bot if you rename the artifact.
111-
- name: Upload conformance suite commit
112-
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
113-
with:
114-
name: conformance-suite-commit
115-
path: conformance-suite-commit

scripts/conformance.py

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@
7070
re.VERBOSE,
7171
)
7272

73-
CONFORMANCE_URL = "https://github.com/python/typing/blob/{conformance_suite_commit}/conformance/tests/{filename}#L{line}"
7473
CONFORMANCE_SUITE_COMMIT = os.environ.get("CONFORMANCE_SUITE_COMMIT", "main")
74+
CONFORMANCE_DIR_WITH_README = (
75+
f"https://github.com/python/typing/blob/{CONFORMANCE_SUITE_COMMIT}/conformance/"
76+
)
77+
CONFORMANCE_URL = CONFORMANCE_DIR_WITH_README + "/tests/{filename}#L{line}"
7578

7679

7780
class Source(Flag):
@@ -89,13 +92,13 @@ class Classification(StrEnum):
8992
def into_title(self) -> str:
9093
match self:
9194
case Classification.TRUE_POSITIVE:
92-
return "True positives added 🎉"
95+
return "True positives added"
9396
case Classification.FALSE_POSITIVE:
94-
return "False positives added 🫤"
97+
return "False positives added"
9598
case Classification.TRUE_NEGATIVE:
96-
return "False positives removed 🎉"
99+
return "False positives removed"
97100
case Classification.FALSE_NEGATIVE:
98-
return "True positives removed 🫤"
101+
return "True positives removed"
99102

100103

101104
@dataclass(kw_only=True, slots=True)
@@ -415,7 +418,7 @@ def render_grouped_diagnostics(
415418
):
416419
group = list(group)
417420

418-
lines.append(f"## {classification.into_title()}")
421+
lines.append(f"### {classification.into_title()}")
419422
lines.extend(["", "<details>", ""])
420423

421424
lines.extend(header)
@@ -478,6 +481,8 @@ def format_metric(diff: float, old: float, new: float):
478481
false_neg_change = new.false_negatives - old.false_negatives
479482
total_change = new.total - old.total
480483

484+
base_header = f"[Typing conformance results]({CONFORMANCE_DIR_WITH_README})"
485+
481486
if (
482487
precision_change == 0
483488
and recall_change == 0
@@ -486,7 +491,13 @@ def format_metric(diff: float, old: float, new: float):
486491
and false_neg_change == 0
487492
and total_change == 0
488493
):
489-
return "## Typing conformance\n\nNo changes"
494+
return dedent(
495+
f"""
496+
## {base_header}
497+
498+
No changes detected ✅
499+
"""
500+
)
490501

491502
true_pos_diff = diff_format(true_pos_change, greater_is_better=True)
492503
false_pos_diff = diff_format(false_pos_change, greater_is_better=False)
@@ -495,9 +506,29 @@ def format_metric(diff: float, old: float, new: float):
495506
recall_diff = diff_format(recall_change, greater_is_better=True)
496507
total_diff = diff_format(total_change, neutral=True)
497508

498-
table = dedent(
509+
if (precision_change > 0 and recall_change >= 0) or (
510+
recall_change > 0 and precision_change >= 0
511+
):
512+
header = f"{base_header} improved 🎉"
513+
elif (precision_change < 0 and recall_change <= 0) or (
514+
recall_change < 0 and precision_change <= 0
515+
):
516+
header = f"{base_header} regressed ❌"
517+
else:
518+
header = base_header
519+
520+
summary_paragraph = (
521+
f"The percentage of diagnostics emitted that were expected errors "
522+
f"{format_metric(precision_change, old.precision, new.precision)}. "
523+
f"The percentage of expected errors that received a diagnostic "
524+
f"{format_metric(recall_change, old.recall, new.recall)}."
525+
)
526+
527+
return dedent(
499528
f"""
500-
## Typing Conformance
529+
## {header}
530+
531+
{summary_paragraph}
501532
502533
### Summary
503534
@@ -513,15 +544,6 @@ def format_metric(diff: float, old: float, new: float):
513544
"""
514545
)
515546

516-
summary = (
517-
f"The percentage of diagnostics emitted that were expected errors"
518-
f" {format_metric(precision_change, old.precision, new.precision)},"
519-
" and the percentage of expected errors that received a diagnostic"
520-
f" {format_metric(recall_change, old.recall, new.recall)}."
521-
)
522-
523-
return "\n".join([table, summary])
524-
525547

526548
def parse_args():
527549
parser = argparse.ArgumentParser(

0 commit comments

Comments
 (0)