Commits

masklinn  committed cbd4572

Make __hash__ return strings instead of numbers, simpler to implement

fixes issue 8

  • Participants
  • Parent commits 1758bfe

Comments (0)

Files changed (1)

             if (this._hash) {
                 return this._hash;
             }
-            return this._hash = hash_counter++;
+            // tagged counter, to avoid collisions with e.g. number hashes
+            return this._hash = '\0\0\0' + String(hash_counter++);
         },
         __eq__: function (other) {
             return (this === other) ? py.True : py.False;
         throw new Error('TypeError: __str__ returned non-string (type ' +
                         v.constructor.name + ')');
     }, py.object, {
+        __hash__: function () {
+            return '\1\0\1' + this._value;
+        },
         __eq__: function (other) {
             if (other instanceof py.str && this._value === other._value) {
                 return py.True;