Skip to content
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

restore length(<delayed_module>) not forcing the module. #1700

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions R/python.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
Loading