Implement external classes#660
Conversation
# Conflicts: # NEWS.md # R/class-spec.R # R/external-generic.R # _pkgdown.yml # tests/testthat/_snaps/property.md
|
@t-kalinowski @lawremi I think this is now ready for your feedback. |
lawremi
left a comment
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.
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)
| } | ||
| } | ||
|
|
||
| # Also consider cases where the constructor isn't named the same as the class |
There was a problem hiding this comment.
Are we sure that this is a case that we want to support? Why do we want to encourage people to have a mismatch between constructor and class name?
| #' Make sure to call [S7_on_load()] in your package's `.onLoad()` so that | ||
| #' deferred method registrations fire when the relevant package is loaded. | ||
| #' | ||
| #' External classes can not currently be used as parents in [new_class()]. |
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.