Calculate return type of lu!(A)

For a given A::M where M <: AbstractMatrix, I would like to calculate typeof(lu!(A)) in the least brittle way. That is,

  1. without exposing internals if possible,

  2. without performing the calculation if possible,

  3. working well at least for usual suspects (eg M = Matrix{Float64}), but ideally for all type stable calls.

  4. returning Any for calls that are not type stable.

(To avoid XY problems: the objective is to build a dictionary, hence I need value types)

typeof(lu!(oneunit(similar(A,1,1)))), maybe?

Thanks! That would tick all boxes except (2), right? EDIT I just saw the dimensions and that the calculation is trivial.

Is

Base.promote_typejoin_union(Base.promote_op(lu!, Matrix{Float64}))

iffy? So many warnings in the docstrings.

ArrayInterface.jl has lu_instance which gives you an empty object of the right type.

I tried a handful of simple cases and wasn’t able to make Base.promote_typejoin_union(Base.promote_op(lu!, typeof(A))) fail. However, it relies on type inference (which can be fragile), and on not one but two non-public Base functions.