Skip to content

Add mypy typing coverage reporting and policy check to CI - #971

Open
mcepl wants to merge 2 commits into
masterfrom
mypy-typing-coverage
Open

mcepl wants to merge 2 commits into
masterfrom
mypy-typing-coverage

Conversation

@mcepl

@mcepl mcepl commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a lightweight, mypy-based typing coverage check to CI to track progress towards typing Rope's codebase (#798).

Inspired by @smheidrich's proposal in #799, this takes a self-contained mypy approach instead of pulling in Node.js/Pyright and a third-party composite action, runs directly against the package as distributed (no temporary py.typed marker), pins mypy and all GitHub Actions to exact commit SHAs, and declares minimal workflow permissions.

Policy & behaviour

Coverage is measured by bin/typing-coverage.py comparing the PR head against its base commit using mypy --lineprecision-report (precise non-empty lines, primary metric; currently ~14.06%) alongside --linecount-report (annotated functions, secondary metric; currently ~7.62%):

  • Below 50% precise-line coverage: strictly informational — always passes and displays coverage changes, progress towards 50%, and a collapsible per-module breakdown.
  • At or above 50% precise-line coverage: a drop of more than 5 percentage points fails the check unless a maintainer explicitly approves it by adding the allow-typing-regression label.
  • PR visibility: .github/workflows/typing-coverage.yml writes the report to the Job Summary (contents: read), and .github/workflows/typing-coverage-comment.yml (workflow_run, pull-requests: write, never checking out PR code) posts and updates a single sticky comment on the PR Conversation tab (activates on subsequent PRs once merged to master).

Refs: #798
Supersedes: #799

Checklist:

  • I have tested the script locally against unchanged, improved, and regressed cases (both below and above the 50% threshold, and with/without the override flag)
  • I have documented the typing coverage policy and local usage in docs/contributing.rst

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.46%. Comparing base (18e7d47) to head (d64b377).

Additional details and impacted files
@@                    Coverage Diff                    @@
##           changelog-news-fragments     #971   +/-   ##
=========================================================
  Coverage                     95.46%   95.46%           
=========================================================
  Files                           134      134           
  Lines                         26946    26946           
=========================================================
  Hits                          25723    25723           
  Misses                         1223     1223           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

mcepl added a commit that referenced this pull request Nov 23, 2026
The "Run tests" and "Run Black" workflows were triggered on both
push and pull_request. For PRs from branches in the upstream
repository this ran every job twice for the same commit, doubling
the load on the scarce macOS runners. On PR #971 the push run
failed only because three macOS jobs were never picked up by a
hosted runner, while the pull_request run of the same commit
passed.

Restrict the push trigger to master, so that PR branches are
tested once through the pull_request event and master is still
tested after merges.
mcepl added a commit that referenced this pull request Nov 23, 2026
The "Run tests" and "Run Black" workflows were triggered on both
push and pull_request. For PRs from branches in the upstream
repository this ran every job twice for the same commit, doubling
the load on the scarce macOS runners. On PR #971 the push run
failed only because three macOS jobs were never picked up by a
hosted runner, while the pull_request run of the same commit
passed.

Restrict the push trigger to master, so that PR branches are
tested once through the pull_request event and master is still
tested after merges.
mcepl added a commit that referenced this pull request Nov 23, 2026
Hosted macOS arm64 runners on GitHub Actions are often short of
capacity, and test jobs targeting them get cancelled with "The
job was not acquired by Runner of type hosted even after
multiple attempts". This happened repeatedly on PR #971, turning
the whole "Run tests" workflow red although no test failed.

Mark the macOS matrix jobs with continue-on-error, so a failing
or never-started macOS job no longer fails the workflow, and add
a 20-minute timeout per job (a test job normally takes about two
minutes), so a hung job cannot run for the default six hours.

Note that the macOS jobs for 3.12, 3.13 and 3.14 are required
status checks in the master branch protection, so a cancelled
required job still blocks merging until it is re-run or the
checks are made non-required.
@mcepl
mcepl force-pushed the mypy-typing-coverage branch from 2c8be1d to f253f40 Compare November 23, 2026 19:02
@mcepl
mcepl force-pushed the mypy-typing-coverage branch from f253f40 to 1c98826 Compare November 30, 2026 08:27
@mcepl
mcepl changed the base branch from master to changelog-news-fragments November 30, 2026 08:27
@mcepl
mcepl added this pull request to stack #986 November 30, 2026 08:27
@mcepl
mcepl requested a review from lieryan November 30, 2026 08:28
@mcepl
mcepl force-pushed the mypy-typing-coverage branch from 1c98826 to 9cf80c2 Compare November 30, 2026 08:28
Nearly every pull request conflicted on the top of CHANGELOG.md,
because all of them appended to the same "Upcoming release"
section. Following a much simplified version of CPython's
blurb/NEWS.d workflow, each PR now adds a small Markdown file
changelog.d/<issue>.md with its entry, so parallel PRs never
touch the same file.

The new bin/news script (plain POSIX sh, so it works on Linux,
the BSDs and macOS) creates a fragment in $VISUAL/$EDITOR from a
template encouraging longer, explanatory entries (`bin/news 123`),
previews the pending release section (`bin/news preview`), and
folds the fragments, sorted by number, into a new "# Release
<version>" section of CHANGELOG.md (`bin/news collect`). A new
portable top-level Makefile wraps it as `make news N=123`,
`make changelog-preview`, `make changelog` and `make release`,
the last of which also builds the documentation via
docs/Makefile; that gains an explicit `html` rule, as its
Sphinx-generated catch-all pattern rule is GNU make only. The
news target passes N and TEXT to bin/news through the
environment ("$$N", "$$TEXT"), so Markdown backticks and quotes
in an entry reach the script literally instead of being
re-parsed by the shell.

The pending entry for the #223 regression tests, previously in
the "Upcoming release" section, has been moved to
changelog.d/223.md, and the PR template, contributing and
release-process docs updated.
@mcepl
mcepl force-pushed the changelog-news-fragments branch from d88420d to 18e7d47 Compare November 30, 2026 08:49
Replace the earlier Pyright-based proposal with a lightweight
mypy-based typing coverage check that avoids Node.js and third-
party composite actions, pins mypy and all GitHub Actions by
commit SHA, and runs directly against the package as distributed
without fabricating a py.typed marker.

The new bin/typing-coverage.py helper compares base and PR
checkouts using mypy --lineprecision-report (primary metric:
precise non-empty lines) and --linecount-report (secondary
metric: annotated functions), enforcing a two-phase policy
documented in docs/contributing.rst:

- Below 50% precise-line coverage, the check is strictly
  informational and always passes.
- At or above 50%, drops greater than 5 percentage points fail
  the check unless a maintainer applies the
  allow-typing-regression label.

A separate workflow_run workflow posts and updates a single
sticky HTML/Markdown summary comment on the pull request without
checking out untrusted PR code.

Refs: #798
Supersedes: #799
@mcepl
mcepl force-pushed the mypy-typing-coverage branch from 9cf80c2 to d64b377 Compare November 30, 2026 08:55
@mcepl
mcepl removed this pull request from stack #986 November 30, 2026 08:58
Base automatically changed from changelog-news-fragments to master December 1, 2026 22:17

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant