[Jython-checkins] jython (2.5): Special case isintance and issubclass so stringmap compares as a dict.
frank.wierzbicki
jython-checkins at python.org
Fri Apr 6 22:54:05 CEST 2012
http://hg.python.org/jython/rev/196e2e8bad7b
changeset: 6542:196e2e8bad7b
branch: 2.5
parent: 6525:1b18d875074e
user: Frank Wierzbicki <fwierzbicki at gmail.com>
date: Fri Apr 06 13:42:28 2012 -0700
summary:
Special case isintance and issubclass so stringmap compares as a dict.
files:
src/org/python/core/Py.java | 24 ++++++++++++++++++++++--
1 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/src/org/python/core/Py.java b/src/org/python/core/Py.java
--- a/src/org/python/core/Py.java
+++ b/src/org/python/core/Py.java
@@ -1899,8 +1899,15 @@
PyClass inClass = (PyClass)inst.fastGetClass();
return inClass.isSubClass((PyClass)cls);
} else if (cls instanceof PyType) {
+ PyType type = (PyType)cls;
+
+ //Special case PyStringMap to compare as an instance type dict.
+ if (inst instanceof PyStringMap &&
+ type.equals(PyDictionary.TYPE)) {
+ return true;
+ }
+
PyType instType = inst.getType();
- PyType type = (PyType)cls;
// equiv. to PyObject_TypeCheck
if (instType == type || instType.isSubType(type)) {
@@ -1946,7 +1953,20 @@
if (derived == cls) {
return true;
}
- return ((PyType) derived).isSubType((PyType) cls);
+
+ PyType type = (PyType)cls;
+ PyType subtype = (PyType)derived;
+
+ // Special case PyStringMap to compare as a subclass of
+ // PyDictionary. Note that we don't need to check for stringmap
+ // subclasses, since stringmap can't be subclassed. PyStringMap's
+ // TYPE is computed lazily, so we have to use PyType.fromClass :(
+ if (type == PyDictionary.TYPE &&
+ subtype == PyType.fromClass(PyStringMap.class)) {
+ return true;
+ }
+
+ return subtype.isSubType(type);
} else if (cls instanceof PyClass && derived instanceof PyClass) {
return ((PyClass) derived).isSubClass((PyClass) cls);
} else if (cls.getClass() == PyTuple.class) {
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list