From 38f764190ff8f8264d6b729ea40fc1d726f5c765 Mon Sep 17 00:00:00 2001 From: Olivier Cots Date: Thu, 23 Jul 2026 12:04:41 +0200 Subject: [PATCH] Fix: Tip line in show(MIME"text/plain", strategy) now shows parameterized type name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Tip message in Base.show(io, MIME"text/plain", strategy) used type_name (just nameof(T)) instead of display_name (which includes the parameter, e.g. DifferentiationInterface{GPU}). This caused the Tip to always show describe(DifferentiationInterface) even for parameterized instances like DifferentiationInterface{GPU}. Changed type_name to display_name in the Tip println call. Updated the docstring example to show both non-parameterized and parameterized cases. Added tests with a fake parameterized strategy (CovFakeParamStrategy{P}) to verify: - Non-parameterized: Tip shows describe(CovFakeStrategy) without {…} - Parameterized: Tip shows describe(CovFakeParamStrategy{CPU}) with {CPU} --- src/Strategies/contract/abstract_strategy.jl | 8 ++- .../test_coverage_abstract_strategy.jl | 49 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/Strategies/contract/abstract_strategy.jl b/src/Strategies/contract/abstract_strategy.jl index 998d1ffe..3c1836e1 100644 --- a/src/Strategies/contract/abstract_strategy.jl +++ b/src/Strategies/contract/abstract_strategy.jl @@ -465,6 +465,12 @@ FakeSolver (instance, id: :fake_solver) ├─ max_iter = 1000 [default] └─ tol = 1.0e-8 [default] Tip: use describe(FakeSolver) to see all available options. + +julia> FakeSolver{CPU}() +FakeSolver{CPU} (instance, id: :fake_solver) +├─ max_iter = 1000 [default] +└─ tol = 1.0e-8 [default] +Tip: use describe(FakeSolver{CPU}) to see all available options. ``` See also: [`CTBase.Strategies.describe`](@ref), [`CTBase.Strategies.options`](@ref) @@ -520,7 +526,7 @@ function Base.show(io::IO, ::MIME"text/plain", strategy::T) where {T<:AbstractSt io, fmt.label, "Tip: use describe(", - type_name, + display_name, ") to see all available options.", fmt.reset, ) diff --git a/test/suite/strategies/test_coverage_abstract_strategy.jl b/test/suite/strategies/test_coverage_abstract_strategy.jl index 8f77de8b..9c3ee0ec 100644 --- a/test/suite/strategies/test_coverage_abstract_strategy.jl +++ b/test/suite/strategies/test_coverage_abstract_strategy.jl @@ -70,6 +70,25 @@ end Strategies.options(s::CovSingleOptStrategy) = s.options +# Fake parameterized strategy for testing Tip display with parameter +struct CovFakeParamStrategy{P} <: Strategies.AbstractStrategy + options::Strategies.StrategyOptions +end + +Strategies.id(::Type{<:CovFakeParamStrategy}) = :cov_fake_param +Strategies.default_parameter(::Type{<:CovFakeParamStrategy}) = Strategies.CPU +Strategies.parameter(::Type{<:CovFakeParamStrategy{P}}) where {P} = P + +function Strategies.metadata(::Type{<:CovFakeParamStrategy{P}}) where {P} + return Strategies.StrategyMetadata( + Options.OptionDefinition(; + name=:max_iter, type=Int, default=100, description="Maximum iterations" + ), + ) +end + +Strategies.options(s::CovFakeParamStrategy) = s.options + # ============================================================================ # Test function # ============================================================================ @@ -134,6 +153,36 @@ function test_coverage_abstract_strategy() Test.@test occursin("value", output) end + Test.@testset "show(io, MIME text/plain) - Tip shows type name without parameter" begin + opts = Strategies.StrategyOptions( + max_iter=Options.OptionValue(200, :user), + tol=Options.OptionValue(1e-8, :default), + ) + strategy = CovFakeStrategy(opts) + + buf = IOBuffer() + show(buf, MIME("text/plain"), strategy) + output = String(take!(buf)) + + Test.@test occursin("Tip: use describe(CovFakeStrategy)", output) + Test.@test !occursin("CovFakeStrategy{", output) + end + + Test.@testset "show(io, MIME text/plain) - Tip shows parameterized type name" begin + opts = Strategies.StrategyOptions( + max_iter=Options.OptionValue(100, :default), + ) + strategy = CovFakeParamStrategy{Strategies.CPU}(opts) + + buf = IOBuffer() + show(buf, MIME("text/plain"), strategy) + output = String(take!(buf)) + + Test.@test occursin( + "Tip: use describe(CovFakeParamStrategy{CPU})", output + ) + end + # ==================================================================== # UNIT TESTS - show(io, strategy) - compact display # ====================================================================