Skip to content

Rename S7_class attribute to _S7_class#689

Merged
hadley merged 4 commits into
mainfrom
s7-class-attribute
Jun 22, 2026
Merged

Rename S7_class attribute to _S7_class#689
hadley merged 4 commits into
mainfrom
s7-class-attribute

Conversation

@hadley

@hadley hadley commented Jun 8, 2026

Copy link
Copy Markdown
Member

This keeps the name as similar as possible, but makes it clear that it's in the namespace S7 reserves for its own usage. This will invalidate S7 objects created with a previous version of S7; let me know if you think I should deal with those automatically.

Closes #677

This keeps the name as similar as possible, but makes it clear that it's in the namespace S7 reserves for its own usage. This will invalidate S7 objects created with a previous version of S7; let me know if you think I should deal with those automatically.

Closes #677
@hadley
hadley requested review from lawremi and t-kalinowski June 8, 2026 19:21

@t-kalinowski t-kalinowski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do think it's worth the effort for us to allow packages built with the current S7 release to work with the next S7 release, for at least one S7 release.

@hadley
hadley requested a review from t-kalinowski June 9, 2026 22:28
@lawremi

lawremi commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

As you've mentioned, the main source of friction with this type of change is that it will break all serialized instances of S7 objects, and it's worth providing an update path.

More generally, Bioconductor has the updateObject() generic for helping with such transitions. I couldn't find much documentation of how updateObject() is used in practice, but basically the class author adds updateObject(x, verbose=TRUE) to accessor methods, where verbose=TRUE outputs a message() reminding the user to call updateObject() to update any serialized instances, while keeping the object valid. Validity methods could also check for obsolete representations and emit a similar error message. Perhaps the tidyverse has its own approach to this. It would be helpful for S7 itself to centrally define an analogous protocol.

@lawremi lawremi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should rely on a general object update protocol (developed as a separate feature, see comment) that directs the user to update any serialized objects. Otherwise, we will always have to support @S7_class, which sort of defeats the purpose of this change.

@hadley

hadley commented Jun 13, 2026

Copy link
Copy Markdown
Member Author

Hmmmm, I was thinking that this was a one off breaking change that we'd make as part of the pre 1.0.0 phase of S7, and since we know that there's relatively limited S7 use we'd eventually drop the code. Since there's relatively little code, the cost of maintaining it is low, and IMO it's worth it because it brings some extra consistency. In principle, I don't think we need to support user @S7_class access because it's an internal slot, which is now clear from the docs.

But it's possible that this problem will come up again in the future, and we should prepare for that. I think the way to do that is to add an interface version to S7 objects so that in the future we could either emit a warning about the serialized object being out of date, or automatically upgrade it using the approach you suggest. That said, I don't think we currently have any hook in base R to call such a function so we'd also need to do some exploration in R itself.

@lawremi lawremi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's a reasonable argument: S7 is currently experimental and subject to change. As adoption is starting to ramp up, it would be good to move to a stable state ASAP. Towards that end, let's remember to remove support for the S7_class attribute after the upcoming release.

@hadley
hadley merged commit 4471eef into main Jun 22, 2026
13 checks passed
@hadley
hadley deleted the s7-class-attribute branch June 22, 2026 22:49
t-kalinowski added a commit that referenced this pull request Jun 23, 2026
* Address external class review findings

* Fix deferred external class method unregistration

* Resolve external class signatures on unload

* Fix external class validation and cleanup

* Fix external-class method hook cleanup

* Fix external class dispatch handling

* Fix deferred external class registration

* Resolve external signatures on method unregister

* Check external class versions before string match

* Remove stale S7 hooks after failed loads

* Reject package-less external class matches

* Normalize external generic sentinels

* Register runtime external-class methods

* Fix deferred external class method registration

* Fix external generic hook replacement

* Short-circuit union class checks

* Address external method registration reviews

* Fix external class union handling

* Remove stale deferred external methods

* Fix external method unregister review cases

* Fix deferred union registration

* Preserve versioned external generic on unregister

* Allow external classes to narrow S7_object

* Simplify external class matching

* Simplify external class cleanup

* Simplify external class registration

* Trim external class changes

* Trim external class cleanup

* Simplify external class resolution

* Simplify external dependency checks

* Use closure for external class validation

* Remove external S7_object special case

* Document generic sentinel invariant

* Trim-external-class-tests

* Clarify-external-package-vignette

* Clarify external class resolution errors

* Restore external class docs example

* Restore external dependency flattening helper

* Simplify external class error construction

* Snapshot external class binding mismatches

* Restore external class default snapshot

* Reduce external class snapshot churn

* Fix external class review findings

[P2] Allow subclasses of external parent classes — /Users/tomasz/github/RConsortium/S7/R/class-spec.R:372-375: Valid narrowing is rejected when a child class is a real S7 subclass of an external parent class. The branch returns FALSE unless the child has the exact same package/name as the external placeholder, so cases like dep::Sub extending dep::Base cannot override a parent property typed as new_external_class("dep", "Base") even though the inheritance chain would make it valid.

[P2] Remove methods when an external class unloads first — /Users/tomasz/github/RConsortium/S7/R/hooks.R:89-90: If the external class package unloads before the downstream package, external_deps_resolvable(deps) is false and unload uses the placeholder signature. Since the method was registered with resolved class objects, unregister_own_S7_method() builds a non-identical method and leaves the downstream method installed in the upstream generic after S7_on_unload().

* Rename `S7_class` attribute to `_S7_class` (#689)

This keeps the name as similar as possible, but makes it clear that it's in the namespace S7 reserves for its own usage. Includes backward compatibility fallback that we can remove in a future version.

Closes #677

* Clarify external class resolution errors

* avoid binding `getNamespaceVersion` in package namespace

* Refactor test helpers to use code blocks (#714)

---------

Co-authored-by: Hadley Wickham <h.wickham@gmail.com>
eitsupi added a commit to pola-rs/r-polars that referenced this pull request Jun 27, 2026
S7 >= 0.3.0 renames the `S7_class` attribute to `_S7_class`
(RConsortium/S7#689). Try `_S7_class` first and fall back to
`S7_class` for backward compatibility with older S7 versions.

Closes #1797
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.

3 participants