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

added type checks for new_object() argument .parent #503

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tschwarzl
Copy link

addressing issue #502

added type checks for new_object() argument .parent asserting that it is of type S7 object not S7_class

…nforcing S7_object and prohibiting S7_class passing.
@tschwarzl tschwarzl changed the title #502 added type checks for new_object() argument .parent added type checks for new_object() argument .parent Nov 22, 2024
Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. This will be a nice improvement in user friendliness.

@@ -238,8 +238,8 @@ is_class <- function(x) inherits(x, "S7_class")

# Object ------------------------------------------------------------------

#' @param .parent,... Parent object and named properties used to construct the
#' object.
#' @param .parent,... Parent S7 object and named properties used to construct
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessarily an S7 object, because the class might extend a base class.

if (!inherits(.parent, "S7_object"))
stop("`.parent` needs to be an S7_object")
if (inherits(.parent, "S7_class")) {
stop(paste("`.parent` cannot be of type S7_class. Did you type",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please put this on two lines and add a snapshot test for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants