Skip to content

Only check method/generic consistency in development contexts - #732

Merged
hadley merged 4 commits into
mainfrom
dev-only-method-checks
Jul 30, 2026
Merged

hadley merged 4 commits into
mainfrom
dev-only-method-checks

Conversation

@hadley

@hadley hadley commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #726. Fixes #728.

check_method()'s consistency diagnostics are only actionable by the developer of one of the packages involved, so this PR only performs them in development contexts, detected by the new in_dev() helper. Outside these contexts — e.g. end user loading an installed downstream package whose upstream has changed a generic — check_method() skips its checks entirely, so the user doesn't see no errors or warnings they can't do anything about (#728). This moves failures from load time, to run time, thus making more R CMD check fixes possible.

Additionally, at load_all() time, we demote the incompatibility errors (exact-formals match for ...-less generics, dispatch-argument mismatch, dispatch-argument defaults) to warnings, so you can still source the package, think fix the problem en masse (#726).

Tests simulate the contexts with new descriptive helpers (local_load_all(), local_R_CMD_check(), local_end_user()), making the existing snapshot tests deterministic regardless of how the test suite itself is run.

🤖 Generated with Claude Code

hadley added 3 commits July 28, 2026 07:55
check_method() now skips its consistency checks unless in_dev() detects a
development context: an active pkgload::load_all(), R CMD check checking a
package involved in the registration (the method's, the generic's, or a
dispatch class's), or a method registered outside of a package. This means
that when an upstream package changes a generic, users of already-installed
downstream packages no longer see errors or warnings that they can't do
anything about (#728).

Additionally, while load_all() is active, incompatibility errors are demoted
to warnings and the offending method is skipped rather than registered, so a
package remains sourceable while its methods are out of sync with a changed
generic, letting you fix them one by one (#726).

Fixes #726. Fixes #728.
in_dev() now returns FALSE while testthat is running (unless load_all() is
active), so method registrations inside a test suite give the same results
under R CMD check (which sets _R_CHECK_PACKAGE_NAME_) as when run locally.
S7's own tests mock is_testing() when simulating an R CMD check context.
@hadley
hadley requested a review from t-kalinowski July 30, 2026 19:44
@hadley
hadley merged commit 642fe0d into main Jul 30, 2026
13 checks passed
@hadley
hadley deleted the dev-only-method-checks branch July 30, 2026 22:07
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.

Can't change default arguments Allow a package to be re-sourced while methods are out of sync with a changed generic

2 participants