Skip to content

Commit b1103b2

Browse files
cpsievertclaude
andcommitted
Fix save_image() compatibility with kaleido v1 (#2475)
Use py_has_attr() instead of tryNULL() to check for kaleido.scopes attribute. Accessing a non-existent Python attribute can throw an AttributeError that may not be caught properly by tryCatch in certain reticulate configurations. Also add force(kaleido) in newKaleidoScope to avoid potential lazy evaluation issues with closures. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4868a68 commit b1103b2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

R/kaleido.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,18 @@ kaleido <- function(...) {
9797
}
9898
)
9999

100-
res <- if (is.null(tryNULL(kaleido$scopes))) {
101-
newKaleidoScope(kaleido)
102-
} else {
100+
res <- if (reticulate::py_has_attr(kaleido, "scopes")) {
103101
legacyKaleidoScope(kaleido)
102+
} else {
103+
newKaleidoScope(kaleido)
104104
}
105105

106106
class(res) <- "kaleidoScope"
107107
res
108108
}
109109

110110
newKaleidoScope <- function(kaleido) {
111+
force(kaleido)
111112
list(
112113
scopes = NULL,
113114
transform = function(p, file, ..., width = NULL, height = NULL, scale = NULL) {

0 commit comments

Comments
 (0)