-
Notifications
You must be signed in to change notification settings - Fork 0
Fix S4 method dispatch on imported S3 generics (e.g. setMethod("as.data.table", "Basket", ...))
#8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
d53131e
e1d67be
dcc3a12
387678b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -441,6 +441,38 @@ check("testthat devpackage: all tests pass", quote( | |
|
|
||
| cat(sprintf(" (testthat devpackage: %d passed, %d failed)\n", n_tt_pass1, n_tt_fail1)) | ||
|
|
||
| # --- S4 method on imported S3 generic (as.data.table) --- | ||
| b1 <- new("Basket", contents = c("apple", "pear")) | ||
|
|
||
| check("Basket class is defined", quote( | ||
| isClass("Basket") | ||
| )) | ||
|
|
||
| check("as.data.table implicit generic is in ns_env (not just the imported S3 fn)", quote( | ||
| is(get("as.data.table", envir = ns, inherits = FALSE), "genericFunction") | ||
| )) | ||
|
|
||
| check("as.data.table in pkg_env is the implicit generic (not overwritten by impenv)", quote( | ||
| is(get("as.data.table", pos = "package:devpackage", inherits = FALSE), "genericFunction") | ||
| )) | ||
|
|
||
| check("as.data.table(Basket) dispatches correctly from ns_env", quote({ | ||
| f <- get("as.data.table", envir = ns) | ||
| dt <- f(b1) | ||
| data.table::is.data.table(dt) && identical(dt$item, c("apple", "pear")) | ||
| })) | ||
|
|
||
| check("as.data.table(Basket) dispatches correctly via search path", quote({ | ||
| f <- get("as.data.table", pos = "package:devpackage") | ||
| dt <- f(b1) | ||
| data.table::is.data.table(dt) && identical(dt$item, c("apple", "pear")) | ||
| })) | ||
|
|
||
| check("exportMethods: as.data.table is in namespace exports", quote( | ||
| "as.data.table" %in% getNamespaceExports("devpackage") | ||
| )) | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot can we also test if normal call works? also for incmrental test. are these new tests exhaustive? can you think of more
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in e1d67be. Both Stage 1 (full load) and Stage 4b (incremental) now cover:
|
||
| # ============================================================================ | ||
| # STAGE 2: Full reload with mutated code (project2-style changes, ad-hoc) | ||
| # ============================================================================ | ||
|
|
@@ -1469,6 +1501,13 @@ check("remove-fn: R6 classes unaffected", quote( | |
| exists("Counter", envir = ns4b, inherits = FALSE) | ||
| )) | ||
|
|
||
| check("incr-reload: Basket method still works via pkg_env after base.R changed", quote({ | ||
| b_incr <- new("Basket", contents = c("x", "y")) | ||
| f <- get("as.data.table", pos = pkg_env4) | ||
| dt <- f(b_incr) | ||
| data.table::is.data.table(dt) && identical(dt$item, c("x", "y")) | ||
| })) | ||
|
|
||
| ns4b_full <- load_fast(tmp_c, helpers = FALSE, attach_testthat = FALSE, full = TRUE) | ||
|
|
||
| check("remove-fn: full=TRUE clears summarize_values from ns", quote( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot remove this. we shouldn't export this method. we only import it. we shouldn't rely on an export
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in dcc3a12. Removed
exportMethods(as.data.table)fromdevpackage/NAMESPACE. The export test now asserts thatas.data.tableis not ingetNamespaceExports("devpackage"), and all direct-call tests were updated fromgetExportedValue()(which requires export) toget("as.data.table", pos = "package:devpackage")(search-path lookup).