Repository navigation
Add deprecated_generic(), deprecated_class(), and deprecated_property() - #734
Merged
Merged
Conversation
Provides a standard way to deprecate parts of an S7 API while keeping old code working: * deprecated_generic() wraps a generic: calls warn then delegate, and method registrations are silently redirected to the replacement. * deprecated_class() aliases a class: the constructor warns, and every other context (signatures, parent, property classes, external class references) silently resolves to the replacement. * deprecated_property() warns on read/write, delegating storage to the replacement property. All three require a `when` version, support deprecation without a replacement (via `old` for generics/classes), and signal with a .Deprecated()-style warning by default; method = "lifecycle(warn)" or "lifecycle(stop)" uses the lifecycle package instead. Also relaxes resolve_external_class_req() so new_external_class() references resolve through exported aliases (plain or deprecated), allowing classes to be renamed without breaking downstream packages. Fixes #727. Fixes #730.
hadley
marked this pull request as ready for review
July 28, 2026 21:21
Keep wrapper arguments separate from deprecation state while preserving lazy evaluation and caller symbol lookup. Route deprecated property access through the property API to preserve validation and NULL handling. Support deprecated classes in unions and report missing deprecation versions consistently across R versions. Add regression coverage.
Resolve deprecated class aliases when checking inheritance and property overrides. Unwrap aliases in generated constructors so internal construction does not emit deprecation warnings. Cover external aliases through public class operations and constructors.
Mark deprecated properties and exclude them before print() and str() read property values. Direct access still signals the configured deprecation. Cover inherited and overridden properties, nested printing, and lifecycle errors. Document the printing behavior. Fixes #754.
Prepend the deprecation marker to the class returned by new_property(), making the extension of a regular property explicit.
t-kalinowski
force-pushed
the
deprecated-helpers
branch
from
September 28, 2026 15:48
f2fabdf to
5c2d72a
Compare
t-kalinowski
added a commit
that referenced
this pull request
Sep 28, 2026
Expand the package-upgrade lab to cover generic and class aliases, package moves, property deprecations, saved instances, and lifecycle signaling. Validate version-1 baselines, distinguish namespace loading from calls, skip tests after failed rebuilds, and support parallel scenario runs. Update the vignette for the helpers in #734 and document their compatibility limits and design gaps. Record all 40 scenarios against the tested revision and include the deprecation design review. Refs #731 and #734.
Allow retired properties to retain their validator. Reject validators on renamed properties and direct users to validate the replacement instead. Document constructor, assignment, and subclass compatibility limits.
Resolve foreign generics in their owning namespace so deprecated aliases share the live method table. Add new_label to name replacement exports without changing class or generic identity. Exercise installed downstream packages before and after rebuilding, including method registration and saved subclass instances.
t-kalinowski
added a commit
that referenced
this pull request
Sep 28, 2026
Use new_label for export renames that preserve class or generic identity, show how to retain validators when retiring properties, and describe namespace-based resolution when moving a generic between packages. Add compatibility scenarios for export labels, property validation, and equal-value property uses under each signaling policy. Refresh the lab results and distinguish supported transitions from the documented limits on installed subclasses, saved instances, and property initialization. Refs #731 and #734.
hadley
commented
Sep 28, 2026
Explain why deprecated aliases support method registration, document property warning behavior, and extract external-class inheritance checks.
Accept class definitions and an optional replacement recommendation in deprecated_class(). Preserve construction, method dispatch, and existing subclasses while warning on direct constructor calls. Resolve deprecated exports silently when constructing property defaults, and update the documentation and package-upgrade regression tests.
t-kalinowski
added a commit
that referenced
this pull request
Sep 29, 2026
Update #731 to describe class deprecation that preserves the original type, with explicit replacement methods and migration boundaries. Expand the package compatibility lab to 59 scenarios, including custom constructors, saved objects, property defaults, and signaling policies. Record the props() lifecycle warning defect and the rebuild requirement for installed direct property defaults as follow-ups for #734.
Resolve property warning callers through base helpers and generated constructors while retaining lifecycle's indirect package-use policy. Document and test the downstream rebuild boundary for direct property defaults under all three signaling policies.
Declare withr as a test dependency and use S7::prop() in the installed package regression test so it also works in R 4.2 subprocesses.
Return the external-class and named-constructor expressions through if/else branches, preserving deferred external-class lookup.
Keep the deprecated/non-deprecated choice as an if/else expression within one return, without nesting the remaining constructor logic.
Use logical subsetting and vapply() with a FALSE prototype when omitting deprecated properties from object printing.
Let package authors replace new_generic() with deprecated_generic() and supply when, keeping dispatch arguments, custom functions, and method registrations. Remove old and retain forwarding through new. Update the documentation and cover direct definitions and downstream method registration across installed-package upgrades.
Use separate returns for deprecated and regular constructor expressions. Use logical(1) as the property filter prototype.
Describe rebuilding against the updated parent package without assigning the build to package maintainers. CRAN or users may also build it.
hadley
commented
Sep 30, 2026
| #' when it is installed. After deprecating a property, downstream packages | ||
| #' need to be rebuilt against the updated parent package so their subclasses | ||
| #' use the new property definition. That build might happen on CRAN, on the | ||
| #' package author's machine, or on the user's machine. Users need to install |
Member
Author
There was a problem hiding this comment.
I feel like this is saying that when you deprecate a class, you break all downstream packages until they've been rebuilt and re-installed.
Member
There was a problem hiding this comment.
The note is trying to say that downstream packages may not start emitting deprecation warnings until they are rebuilt. I've updated the docs to hopefully make that clearer.
Keep both NEWS entries for compact S3 defaults and deprecated-property printing while integrating the latest changes from main.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #727. Fixes #730. Fixes #754.
This PR adds a standard way to deprecate the pieces of an S7 API — generics, classes, and properties — so that old code keeps working but warns users to update.
API
All three helpers require
when(the package version when the deprecation began) and share amethodargument controlling how the deprecation is signalled:"base"(the default, a.Deprecated()-style warning attributed to the user's call),"lifecycle(warn)", or"lifecycle(stop)". The lifecycle options require lifecycle as a dependency of the deprecating package.deprecated_generic()Calling the old name warns then delegates to the target (via call rewriting, so arguments pass through lazily and unmodified).
method<-,method(),method_explain(),S7_methods(), and deferred external-generic registrations all silently unwrap to the target, so downstream packages keep installing and working. This also mitigates #729 for renames: a stale downstream registration finds the deprecated object and resolves through it.deprecated_class()Calling the constructor warns then constructs an instance of
new. In every other context (as_class()is the chokepoint: method signatures,parent, property classes, unions,convert(),S7_inherits(),new_external_class()resolution) the alias is silently treated as the replacement. The no-replacement form mirrors the generic:Cat := deprecated_class(old = Cat, when = "3.0.0").deprecated_property()Generalizes the getter/setter pattern from
vignette("classes-objects")(which now uses it): reading or writing the old name warns and delegates to the replacement, and the generateddefaultmeans the constructor only warns when the deprecated argument is actually supplied. With nonew, the property stores data itself and warns on access (construction can't warn in that case, since S7 can't distinguish a user-supplied value from the default).Default
print()andstr()omit properties created bydeprecated_property()without calling their getters, preventing deprecation warnings or errors during printing (#754). Direct access still signals the configured deprecation. Internally, anS7_deprecated_propertyclass marker identifies the properties to omit.new_external_class()now resolves aliases (#727)resolve_external_class_req()no longer requires the exported object's@name/@packageto match the reference, so a class renamed with a plain alias (Foo <- Bar) or adeprecated_class()keeps working for downstream packages.