Skip to content

Python-side conversion of string doesn't preserve equality #717

@oxinabox

Description

@oxinabox

with

import juliacall
import Main from juliacall as jl

The following all return false.
I expected them all to return True

jl.String("a") == juliacall.convert(jl.String, "a")
"a" == juliacall.convert(jl.String, "a")
juliacall.convert(jl.String, "a") == jl.String("a")

The following do return true:

jl.String("a") == jl.String("a")
juliacall.convert(jl.String, "a") == juliacall.convert(jl.String, "a")
"a" == jl.String("a")

I think what is going wrong is that juliacall.convert wraps the string in an AnyValue even though it doesn't have to.
Where is jl.String actually doesn't:

In : type(juliacall.convert(jl.String, "a"))
Out: juliacall.AnyValue

In : type(jl.String("a"))
Out: str

And AnyValue does not overload equality.
In contrast other similar types return wrapper types that do.

In : type(juliacall.convert(jl.Float64, 1.5))
Out: juliacall.RealValue

In : juliacall.convert(jl.Float64, 1.5) == 1.5
Out: True

In : type(juliacall.convert(jl.Bool, True))
Out: juliacall.IntegerValue

In : juliacall.convert(jl.Bool, True) == True
Out: True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions