Skip to content

Refine external class resolution and deferred methods - #710

Merged
t-kalinowski merged 48 commits into
external-classfrom
external-class-followup
Jun 23, 2026
Merged

t-kalinowski merged 48 commits into
external-classfrom
external-class-followup

Conversation

@t-kalinowski

Copy link
Copy Markdown
Member

Summary

  • Tighten external class resolution so new_external_class() matches an S7
    class bound to the requested name and package, with clearer failure messages.
  • Improve external-class behavior in property inheritance, union matching,
    version checks, and validation errors.
  • Simplify deferred external method registration/unregistration and hook cleanup
    for external classes and generics.
  • Update tests, snapshots, and the package vignette to reflect the narrower
    external-class contract.

Public-facing changes

  • new_external_class() now documents and reports the class binding contract
    more directly.
  • External-class methods and unions behave more consistently when dependency
    packages load, unload, or are not yet available.

Internal-only changes

  • Refactors dependency collection, hook registration/removal, external generic
    sentinels, and deferred method cleanup without adding exported API.

@t-kalinowski
t-kalinowski force-pushed the external-class-followup branch from 3bb01d4 to 4aee542 Compare June 19, 2026 20:54
t-kalinowski and others added 9 commits June 19, 2026 17:08
[P2] Allow subclasses of external parent classes — /Users/tomasz/github/RConsortium/S7/R/class-spec.R:372-375: Valid narrowing is rejected when a child class is a real S7 subclass of an external parent class. The branch returns FALSE unless the child has the exact same package/name as the external placeholder, so cases like dep::Sub extending dep::Base cannot override a parent property typed as new_external_class("dep", "Base") even though the inheritance chain would make it valid.

[P2] Remove methods when an external class unloads first — /Users/tomasz/github/RConsortium/S7/R/hooks.R:89-90: If the external class package unloads before the downstream package, external_deps_resolvable(deps) is false and unload uses the placeholder signature. Since the method was registered with resolved class objects, unregister_own_S7_method() builds a non-identical method and leaves the downstream method installed in the upstream generic after S7_on_unload().
This keeps the name as similar as possible, but makes it clear that it's in the namespace S7 reserves for its own usage. Includes backward compatibility fallback that we can remove in a future version.

Closes #677
# Conflicts:
#	tests/testthat/helper.R
#	tests/testthat/test-method-register.R
@t-kalinowski
t-kalinowski marked this pull request as ready for review June 23, 2026 13:39
@t-kalinowski
t-kalinowski merged commit 9968303 into external-class Jun 23, 2026
13 checks passed
@t-kalinowski
t-kalinowski deleted the external-class-followup branch June 23, 2026 14:39
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.

2 participants