LearnAPI.clone calls the advertised keyword constructor positionally
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 45
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
While working on a downstream package (OnlineML.jl), I noticed a discrepancy between the constructor trait documentation and the actual implementation of LearnAPI.clone.
The constructor trait documentation requires a keyword constructor and demonstrates reconstruction with:
LearnAPI.constructor(learner)(; named_properties...)
However, LearnAPI.clone currently collects the learner properties and passes them as positional arguments by splatting a NamedTuple without a semicolon:
LearnAPI.constructor(learner)(NamedTuple{names}(new_values)...)
Minimal reproducer
using LearnAPI
Base.@kwdef struct DemoLearner
rate::Float64 = 0.1
end
LearnAPI.constructor(::DemoLearner) = DemoLearner
LearnAPI.clone(DemoLearner(); rate=0.2)
Expected Behavior
DemoLearner(0.2) should be returned through the documented keyword-constructor contract (e.g., if clone splatted with a semicolon: ; NamedTuple{names}(new_values)...).
Actual Behavior
clone calls DemoLearner(0.2) positionally. A learner that intentionally provides only the documented keyword constructor (like the one generated by Base.@kwdef without a custom positional fallback) raises a MethodError.
Additional Context
Currently, downstream learners with properties must provide an additional positional constructor solely for compatibility with LearnAPI.clone.
Fixing this by changing clone to splat the named tuple as keywords (;) would align the code with the documentation. However, please note that changing clone upstream may affect existing learners that have already implemented (or only implemented) a positional constructor to work around this, so an upstream compatibility transition/deprecation phase might be necessary.
Affected code
Possible change
return LearnAPI.constructor(learner)(; NamedTuple{names}(new_values)...)
PS : this issue have been filled with AI assistance
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at src/clone.jl around line 26 and compare the constructor call with the keyword-constructor contract described in the issue. Run the DemoLearner reproducer to verify the failure, then confirm that clone works with the documented keyword-only constructor and consider the compatibility impact on existing positional constructors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- api, machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100