Skip to content

Commit 7a93b09

Browse files
committed
add constructor trait; base docstring fallback on this if u can
1 parent 0d28a11 commit 7a93b09

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/MLJModelInterface.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const MODEL_TRAITS = [
3333
:reports_feature_importances,
3434
:deep_properties,
3535
:reporting_operations,
36+
:constructor,
3637
]
3738

3839
const ABSTRACT_MODEL_SUBTYPES = [

src/model_traits.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@ const DeterministicDetector = Union{
1313

1414
const StatTraits = StatisticalTraits
1515

16+
# note that if F is a constructor, like `TunedModel`, then `docstring(F)` already falls
17+
# back to the function's document string.
1618
function StatTraits.docstring(M::Type{<:Model})
17-
docstring = Base.Docs.doc(M) |> string
19+
constructor = StatTraits.constructor(M)
20+
# At time of writing, `constructor` is a new trait only overloaded for model wrappers
21+
# that have multiple types associated with the same constructor (e.g., `TunedModel` is
22+
# a constructor that can return objects of either `ProbabilisticTunedModel` or
23+
# `DeterministicTunedModel` type. However, we want these bound to the same docstring.
24+
C = isnothing(constructor) ? M : constructor
25+
docstring = Base.Docs.doc(C) |> string
1826
if occursin("No documentation found", docstring)
19-
docstring = synthesize_docstring(M)
27+
docstring = synthesize_docstring(C)
2028
end
2129
return docstring
2230
end

0 commit comments

Comments
 (0)