Skip to content

Commit

Permalink
add constructor trait; base docstring fallback on this if u can
Browse files Browse the repository at this point in the history
  • Loading branch information
ablaom committed Jun 3, 2024
1 parent 0d28a11 commit 7a93b09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/MLJModelInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const MODEL_TRAITS = [
:reports_feature_importances,
:deep_properties,
:reporting_operations,
:constructor,
]

const ABSTRACT_MODEL_SUBTYPES = [
Expand Down
12 changes: 10 additions & 2 deletions src/model_traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ const DeterministicDetector = Union{

const StatTraits = StatisticalTraits

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

0 comments on commit 7a93b09

Please sign in to comment.