Skip to content

Conversation

@dgkf
Copy link
Contributor

@dgkf dgkf commented Nov 26, 2025

Closes #579

  • In calls to prop and prop<-, I've remapped attribute names for use in Rf_setAttrib in prop_ and prop_set_ respectively.
  • In new_class, remaps attributes where they're assigned directly
  • Still raises an error for ... as it raises a parse error when trying to use it via obj@..., but this is an R syntax error and it would still work via prop(obj, "..."). I'd probably lean toward even permitting this, but it seemed explicitly undesirable in Defining a property named "..." should not be allowed #442
  • Added a few tests
  • Affected files were also formatted by air, let me know if you'd like whitespace changes reverted.

Comment on lines 196 to 199
prop <- function(object, name) {
.Call(prop_, object, name)
attr_name <- remap_reserved_names(name)
.Call(prop_, object, name, attr_name)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the primary change. attr_name was added as an additional parameter to prop_ (and prop_set_).

It only differs from name in cases when there's a clash with a reserved name, in which case it gets mangled, such as .__S7_prop_names__.

Attributes get remapped at this point so that they keep their user-facing name for all other purposes.

@dgkf dgkf force-pushed the dgkf/mangle-forbidden-names branch from 30bf0fa to 2c7b645 Compare November 26, 2025 18:48
@dgkf dgkf force-pushed the dgkf/mangle-forbidden-names branch from 2c7b645 to b9f6cb8 Compare November 26, 2025 18:52
Comment on lines 289 to 295
attrs <- c(
list(class = class_dispatch(class), S7_class = class),
args[!has_setter],
with_remap_reserved_names(args[!has_setter]),
attributes(object)
)
attrs <- attrs[!duplicated(names(attrs))]
attributes(object) <- attrs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When arguments are passed through new_object() they are assigned to attribute values directly, so they go through the same remapping for reserved names here.

@dgkf dgkf changed the title Feature: perrmit (most) reserved attributes names as property names Feature: permit (most) reserved attributes names as property names Nov 26, 2025
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.

Allow fallback method of storing properties for "forbidden" names

1 participant