I have defined a custom type to wrap a Python library similarly to what SymPy.jl does. So I will focus on a custom defined for SymPy but essentially the problem is the same for my custom type too.

If I define a symmetric matrix as:

using LinearAlgebra, SymPy
x = Matrix{Sym}(undef, 2, 2)
Symmetric(x)

the type of the output is 2×2 Symmetric{Any,Array{Sym,2}}, while if I defined as

Symmetric{eltype(x),typeof(x)}(x, 'L')

the return type is 2×2 Symmetric{Sym,Array{Sym,2}}.

That means that the eltype in the definition of Symmetric returns type Any. Why is this happening and how can I resolve that? Thanks!

You’re looking at a really old version of Julia there. You’re probably running 1.1 or somesuch — the function that’s now called is this:

Symmetric is now recursive so it needs to reason about the transpose of things — and if it can’t then it just gives up and says Any. I’m not sure what all you need to do for a custom type.