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

[R-package] make finalize() in R6 classes private #6833

Merged
merged 1 commit into from
Feb 17, 2025
Merged

Conversation

jameslamb
Copy link
Collaborator

From the {R6} docs:

NOTE: In R6 version 2.3.0 (released 2018-10-04) and below, the $finalize() method could only be public. As of version 2.4.0, it can be public or private. Private is preferable because there’s no reason a finalizer needs to be publicly accessible. If you use a private finalizer in an R package, you should set your R6 version dependency to R6 (>= 2.4.0). In 2.6.0, R6 prints a message if a finalizer is public. In a future version, it will emit warnings, and finally, it will no longer support public finalizers.

ref: https://r6.r-lib.org/articles/Introduction.html

Given that last statement ("... and finally, it will no longer support public finalizers"), I think {lightgbm}'s R6 finalizers should be moved to private methods.

This proposes:

  • making finalize() methods on R6 classes private
  • adding a floor of R6 (>= 2.4.0) to make that safe

Notes for Reviewers

{R6} 2.4.0 was released 6 years ago, in February 2019: https://github.com/r-lib/R6/releases/tag/v2.4.0

So this new floor of >= 2.4.0 should not cause much disruption.

However, still marking this PR as breaking because it removes a public method from the R6 classes in {lightgbm}. Those are not exported, but they're technically still part of the public API because they can be returned by exported functions (e.g. lgb.train() returns a Booster).

Copy link
Collaborator

@StrikerRUS StrikerRUS left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@StrikerRUS StrikerRUS merged commit 3fad53b into master Feb 17, 2025
49 checks passed
@StrikerRUS StrikerRUS deleted the r/r6-finalize branch February 17, 2025 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants