Implement external classes#660
Open
hadley wants to merge 20 commits into
Open
Conversation
# Conflicts: # NEWS.md # R/class-spec.R # R/external-generic.R # _pkgdown.yml # tests/testthat/_snaps/property.md
Member
Author
|
@t-kalinowski @lawremi I think this is now ready for your feedback. |
lawremi
approved these changes
Jun 13, 2026
lawremi
left a comment
Collaborator
There was a problem hiding this comment.
This is a very useful feature. Implementation looks good.
Add regression tests for method registration outside packages, external classes nested in union signatures, and unresolved external class introspection.
Cover resolving external classes whose S7 name differs from their namespace binding, preserving generic sentinels for deferred foreign methods, and rejecting unprovable property overrides involving unresolved external classes.
Resolve external classes by S7 class name, preserve generic sentinels when deferring methods for foreign generics with external-class signatures, and avoid treating unresolved external classes as an empty inheritance hierarchy.
Comment on lines
+172
to
+178
| ( | ||
| identical(S7_class_name(obj), x$class_name) || | ||
| ( | ||
| identical(obj@name, x$name) && | ||
| (is.null(obj@package) || identical(obj@package, x$package)) | ||
| ) | ||
| ) |
Contributor
There was a problem hiding this comment.
[air] reported by reviewdog 🐶
Suggested change
| ( | |
| identical(S7_class_name(obj), x$class_name) || | |
| ( | |
| identical(obj@name, x$name) && | |
| (is.null(obj@package) || identical(obj@package, x$package)) | |
| ) | |
| ) | |
| (identical(S7_class_name(obj), x$class_name) || | |
| (identical(obj@name, x$name) && | |
| (is.null(obj@package) || identical(obj@package, x$package)))) |
t-kalinowski
approved these changes
Jun 16, 2026
Member
There was a problem hiding this comment.
I pushed tests and fixes for some edge cases. Can you please take a look and see if the approach makes sense?
An open question is what behavior we want for property override checks when an external class is from a package that is not loaded yet. The current fix avoids treating an unresolved external class as matching every child type, but it's possible we want to take a different approach here (e.g., defer until the package is loaded, or load the package eagerly)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I think the use of external is a little bit misleading here, because these are really "delayed" classes. But external matches external generic, which exist for a similar reason.
Fixes #250. Fixes #573.
Note this does not solve #317, since currently creating a subclass will force loading of the package via
class_constructor(). But I think can fix that after #694 by using...to call constructors from other packages. That will decouple the superclass arguments from the subclass in a way that won't causeR CMD checkto fail with a codoc mismatch if the parent args change.