Transcrypt icon indicating copy to clipboard operation
Transcrypt copied to clipboard

Dictionary equality comparison differs from CPython

Open JennaSys opened this issue 5 years ago • 2 comments

I'm not sure if this a known difference with CPython, but when comparing dictionaries for equality, the transpiled JS always returns false. I assume this has to do with how JavaScript compares objects in general. For example:

Python Code:

def dict_test():
    x = {'a': 12, 'c': 99, 'b': 54}
    y = {'a': 12, 'b': 54, 'c': 99}
    print(x == y)

# returns True

Transcrypted Code:

export var dict_test = function () {
    var x = dict({"a": 12, "c": 99, "b": 54});
    var y = dict({"a": 12, "c": 99, "b": 54});
    print(x == y)
};

// returns false

I'm assuming the only solution would be to do a recursive comparison of values, or use a 3rd party library like Lodash's _.isEqual() function.

JennaSys avatar Sep 09 '20 23:09 JennaSys

There is no dict comparison code in Transcrypt, I have already reported it in: https://github.com/QQuick/Transcrypt/issues/721

faerot avatar Oct 05 '20 14:10 faerot

It is not a known difference but an omission. Will classify it as enhancement with #721 Thanks!

JdeH avatar Nov 02 '20 08:11 JdeH