From d7adb2c610e1658a897d7f9d2cead06593d4e2dc Mon Sep 17 00:00:00 2001 From: Tomasz Kalinowski Date: Thu, 14 Nov 2024 13:26:56 -0500 Subject: [PATCH] restore `length()` not forcing the module. This is a partial followup to #1688 --- R/python.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/python.R b/R/python.R index abdeaf6a..c2e9b31a 100644 --- a/R/python.R +++ b/R/python.R @@ -819,7 +819,10 @@ length.python.builtin.list <- function(x) { length.python.builtin.object <- function(x) { # return 0 if Python not yet available - if (py_is_null_xptr(x) || !py_available()) + # Note: some packages (rgeedim) use `length(module) == 0` as a way to check if + # an object is a delayed module without forcing it to load. + # Note, a better way to check is: reticulate::py_module_available("module_name") + if (py_is_module_proxy(x) || !py_available() || py_is_null_xptr(x)) return(0L) # otherwise, try to invoke the object's __len__ method @@ -1067,7 +1070,7 @@ py_str.python.builtin.object <- function(object, ...) { #' @export format.python.builtin.module <- function(x, ...) { - if(py_is_module_proxy(x)) + if (py_is_module_proxy(x)) return(paste0("Module(", get("module", envir = x), ")", sep = "")) NextMethod() }