Skip to content

Commit d2c7431

Browse files
committed
fix PyStringMap and PyDictionary comparison
1 parent 36c49a6 commit d2c7431

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/org/python/core/PyStringMap.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
*/
55
package org.python.core;
66

7+
import org.python.expose.ExposedClassMethod;
8+
import org.python.expose.ExposedMethod;
9+
import org.python.expose.ExposedNew;
10+
import org.python.expose.ExposedType;
11+
import org.python.util.Generic;
12+
713
import java.util.Collection;
814
import java.util.Iterator;
915
import java.util.Map;
10-
import java.util.Set;
1116
import java.util.Map.Entry;
17+
import java.util.Set;
1218
import java.util.concurrent.ConcurrentHashMap;
1319
import java.util.concurrent.ConcurrentMap;
1420

15-
import org.python.expose.ExposedClassMethod;
16-
import org.python.expose.ExposedMethod;
17-
import org.python.expose.ExposedNew;
18-
import org.python.expose.ExposedType;
19-
import org.python.expose.MethodType;
20-
import org.python.util.Generic;
21-
2221
/**
2322
* Special fast dict implementation for __dict__ instances. Allows interned String keys in addition
2423
* to PyObject unlike PyDictionary.
@@ -526,13 +525,21 @@ public boolean isSequenceType() {
526525
@Override
527526
public PyObject richCompare(PyObject other, CompareOp op) {
528527
if (op == CompareOp.EQ && other instanceof PyDictionary) {
529-
for (PyObject key: ((PyDictionary) other).keys_as_list().asIterable()) {
530-
if (!get(key).equals(((PyDictionary) other).get(key))) {
528+
PyDictionary otherDict = (PyDictionary) other;
529+
if (!keys().__eq__(otherDict.dict_keys()).__bool__()) {
530+
return Py.False;
531+
}
532+
for (PyObject key: otherDict.keys_as_list().asIterable()) {
533+
if (!get(key).equals(otherDict.get(key))) {
531534
return Py.False;
532535
}
533536
}
534537
return Py.True;
535538
}
539+
if (op == CompareOp.EQ && other instanceof PyStringMap) {
540+
PyStringMap otherDict = (PyStringMap) other;
541+
return otherDict.table.equals(table) ? Py.True : Py.False;
542+
}
536543
return super.richCompare(other, op);
537544
}
538545

src/org/python/core/StringFormatter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ int getNumber() {
9696
char c = pop();
9797
if (c == '*') {
9898
PyObject o = getarg();
99-
if (o instanceof PyInteger) {
100-
return ((PyInteger)o).getValue();
99+
if (o instanceof PyLong) {
100+
return ((PyLong)o).asInt();
101101
}
102102
throw Py.TypeError("* wants int");
103103
} else {

0 commit comments

Comments
 (0)