Hi Everyone,
Happy New Year!
Thanks for the continued work on Brython, it is great. Your time on the project is appreciated.
I have been using it in a project, and have come across some unexpected behaviour with keys for dictionary:
Here is a minimum working example:
<html>
<head>
<script type="text/javascript"
</script>
<!--
<script type="text/javascript"
</script>
-->
<script type="text/python">
from browser import document, alert, window
def pyEntry():
print( hash( (1,3) ) )
print( hash( (-1,3) ) )
print( hash( (1,-3) ) )
print( hash( (-1,-3) ) )
d = {}
d[ (1,3) ] = None
d[ (-1,3) ] = None
d[ (1,-3) ] = None
d[ (-1,-3) ] = None
#d[ "JLKJ" ] = 2
print("Hello")
print( d )
window.pyEntry = pyEntry
</script>
<script>
function jsEntry() {
brython(1);
window.pyEntry()
}
</script>
</head>
<body onload="jsEntry()">
</body>
</html>
Gives the following output:
brython.js:4896 219750520
brython.js:4896 -219750522
brython.js:4896 -219750522
brython.js:4896 219750520
brython.js:4896 Eq: False
brython.js:4896 Hello
brython.js:4896 {(-1, -3): None, (1, -3): None}
I am not familiar with Python dictionary implementations, but I think its hashing with open addressing
It looks like the hashes for different tuples are the same. (I think this is allowed)
It looks like they compare for equality correctly.
Perhaps there is something wrong with the dictionary lookup implementation, that there is not a check for equality, as well as the hash??
Should I file a bug-report somewhere?
Best wishes,
Mike