Skip to content

Commit e091a56

Browse files
committed
Fix attribute selection for doBuiltinTypeType specialization in PyObjectLookupAttrNode.
The `doBuiltinTypeType` specialization only applies for non-type-slot attributes. Previously it was assumed that all type slots have underscore names, however, "mro" also exists and needs to be checked for. This is now implemented in the `isNotTypeSlot()` helper function.
1 parent 585c0e5 commit e091a56

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectLookupAttr.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ protected static boolean isTypeGetAttribute(Object lazyClass) {
118118
return getAttributeIs(lazyClass, BuiltinMethodDescriptors.TYPE_GET_ATTRIBUTE);
119119
}
120120

121+
protected static final boolean isBuiltinTypeType(Object type) {
122+
return type == PythonBuiltinClassType.PythonClass;
123+
}
124+
125+
protected static final boolean isNotTypeSlot(String name) {
126+
final int length = name.length();
127+
return length < 3 || (length > 3 && name.charAt(0) != '_') || !name.equals("mro");
128+
}
129+
121130
// simple version that needs no calls and only reads from the object directly
122131
@SuppressWarnings("unused")
123132
@Specialization(guards = {"isObjectGetAttribute(type)", "hasNoGetAttr(type)", "name == cachedName", "isNoValue(descr)"})
@@ -166,19 +175,11 @@ static final Object doBuiltinModule(VirtualFrame frame, Object object, String na
166175
}
167176
}
168177

169-
protected static final boolean isBuiltinTypeType(Object type) {
170-
return type == PythonBuiltinClassType.PythonClass;
171-
}
172-
173-
protected static final boolean isNotUnderscoreName(String name) {
174-
return name.length() < 4 || name.charAt(0) != '_';
175-
}
176-
177178
// simple version that needs no calls and only reads from the object directly. the only
178179
// difference for type.__getattribute__ over object.__getattribute__ is that it looks for a
179180
// __get__ method on the value and invokes it if it is callable.
180181
@SuppressWarnings("unused")
181-
@Specialization(guards = {"isTypeGetAttribute(type)", "isBuiltinTypeType(type)", "isNotUnderscoreName(name)"}, limit = "1")
182+
@Specialization(guards = {"isTypeGetAttribute(type)", "isBuiltinTypeType(type)", "isNotTypeSlot(name)"}, limit = "1")
182183
static final Object doBuiltinTypeType(VirtualFrame frame, Object object, String name,
183184
@Cached GetClassNode getClass,
184185
@Bind("getClass.execute(object)") Object type,

0 commit comments

Comments
 (0)