oracle / graalpython

GraalPy – A high-performance embeddable Python 3 runtime for Java
https://www.graalvm.org/python/
Other
1.24k stars 108 forks source link

Python "==" returns false for Java strings #293

Closed kfirt closed 1 year ago

kfirt commented 2 years ago

Seems like there is a regression in 22.3.0 when using java Maps. Using the code below

    public static void main(String[] args) {
        Context ctx = Context.newBuilder().allowAllAccess(true).build();
        String workflowScript = """
                def enrich(mymap):
                    print(type(mymap))
                    print(mymap['source'] == 'foo')
                    print(mymap.get('source') == 'foo')
                """;

        ctx.eval("python", workflowScript);
        Map source = Map.of("source", "foo");
        ctx.getBindings("python").getMember("enrich").execute(source);
    }

If you could also remove the assertions from com.oracle.graal.python.nodes.truffle.TruffleStringMigrationHelpers it will ease running JUnit tests on our end

timfel commented 2 years ago

As discussed on Slack, the issue with == is that our str.__eq__ implementation does not support j.l.String instances anymore, only our new internal type TruffleString. We will fix this use case for the next release

timfel commented 1 year ago

The fix for this is now on master, and will be released with 23.0.0 in January. The reproducer you have provided was added to our test suite so we won't regress on this again. Thank you for your help in tracking this down!