Skip to content

Add deprecated_generic(), deprecated_class(), and deprecated_property() - #734

Merged
t-kalinowski merged 22 commits into
mainfrom
deprecated-helpers
Oct 1, 2026
Merged

t-kalinowski merged 22 commits into
mainfrom
deprecated-helpers

Conversation

@hadley

@hadley hadley commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

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 a method argument 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()

# renamed
summarise := deprecated_generic(new = summarize, when = "1.1.0")

# retired with no replacement
shout := new_generic("x")
shout := deprecated_generic(old = shout, when = "2.0.0")

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()

Dog := deprecated_class(new = Pet, when = "2.0.0")

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()

Basket := new_class(
  properties = list(
    size = class_double,
    deprecated_property("count", new = "size", when = "1.5.0")
  )
)

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 generated default means the constructor only warns when the deprecated argument is actually supplied. With no new, 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() and str() omit properties created by deprecated_property() without calling their getters, preventing deprecation warnings or errors during printing (#754). Direct access still signals the configured deprecation. Internally, an S7_deprecated_property class 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/@package to match the reference, so a class renamed with a plain alias (Foo <- Bar) or a deprecated_class() keeps working for downstream packages.

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
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 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.
Comment thread R/class-spec.R Resolved
Comment thread R/class-spec.R Resolved
Comment thread R/deprecated.R Resolved
Comment thread R/deprecated.R Resolved
Comment thread R/deprecated.R Resolved
Comment thread R/deprecated.R Resolved
Comment thread R/deprecated.R Resolved
Comment thread R/deprecated.R Resolved
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.
t-kalinowski added a commit that referenced this pull request Sep 29, 2026
Update #731's design review and package compatibility results against the
corrected lifecycle caller lookup. Describe installed direct property
defaults as a documented rebuild requirement, with regression coverage in
#734.
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.
Comment thread R/deprecated.R Outdated
#' 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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

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.

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.
@t-kalinowski
t-kalinowski merged commit 245aaf4 into main Oct 1, 2026
15 of 16 checks passed
@t-kalinowski
t-kalinowski deleted the deprecated-helpers branch October 1, 2026 17:48
t-kalinowski added a commit that referenced this pull request Oct 1, 2026
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.

Default print() and str() trigger deprecated property warnings Can't deprecate generics Can't rename classes

2 participants