Skip to content

Commit 6cf9e29

Browse files
committed
More test fixes
1 parent b6dd540 commit 6cf9e29

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,12 @@ public static Object updateSequence(VirtualFrame frame, PDict self, Object[] arg
590590
return PNone.NONE;
591591
}
592592

593+
@Specialization(guards = "args.length > 1")
594+
@SuppressWarnings("unused")
595+
Object error(PDict self, Object[] args, PKeyword[] kwargs) {
596+
throw raise(TypeError, ErrorMessages.EXPECTED_AT_MOST_D_ARGS_GOT_D, "update", 1, args.length);
597+
}
598+
593599
protected static boolean isDict(Object[] args) {
594600
return args.length == 1 && args[0] instanceof PDict;
595601
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static Object getClass(Object self, @SuppressWarnings("unused") PNone value,
161161

162162
@Specialization(guards = "isNativeClass(klass)")
163163
Object setClass(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object klass) {
164-
throw raise(TypeError, ErrorMessages.CLASS_ASSIGMENT_ONLY_SUPPORTED_FOR_HEAP_TYPES_OR_MODTYPE_SUBCLASSES);
164+
throw raise(TypeError, ErrorMessages.CLASS_ASSIGNMENT_ONLY_SUPPORTED_FOR_HEAP_TYPES_OR_MODTYPE_SUBCLASSES);
165165
}
166166

167167
@Specialization(guards = "isPythonClass(value) || isPythonBuiltinClassType(value)")
@@ -173,7 +173,7 @@ PNone setClass(VirtualFrame frame, PythonObject self, Object value,
173173
@Cached GetClassNode getClassNode) {
174174
Object type = getClassNode.execute(self);
175175
if (isBuiltinClassNotModule(value, classProfile1) || PGuards.isNativeClass(value) || isBuiltinClassNotModule(type, classProfile2) || PGuards.isNativeClass(type)) {
176-
throw raise(TypeError, ErrorMessages.CLASS_ASSIGMENT_ONLY_SUPPORTED_FOR_HEAP_TYPES_OR_MODTYPE_SUBCLASSES);
176+
throw raise(TypeError, ErrorMessages.CLASS_ASSIGNMENT_ONLY_SUPPORTED_FOR_HEAP_TYPES_OR_MODTYPE_SUBCLASSES);
177177
}
178178

179179
checkCompatibleForAssigmentNode.execute(frame, type, value);
@@ -187,7 +187,7 @@ private static boolean isBuiltinClassNotModule(Object type, IsBuiltinClassProfil
187187

188188
@Specialization(guards = {"isPythonClass(value) || isPythonBuiltinClassType(value)", "!isPythonObject(self)"})
189189
Object getClass(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused") Object value) {
190-
throw raise(TypeError, ErrorMessages.CLASS_ASSIGMENT_ONLY_SUPPORTED_FOR_HEAP_TYPES_OR_MODTYPE_SUBCLASSES);
190+
throw raise(TypeError, ErrorMessages.CLASS_ASSIGNMENT_ONLY_SUPPORTED_FOR_HEAP_TYPES_OR_MODTYPE_SUBCLASSES);
191191
}
192192

193193
@Fallback

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ private static Object bestBase(PythonAbstractClass[] bases, GetSolidBaseNode get
830830
public abstract static class CheckCompatibleForAssigmentNode extends PNodeWithContext {
831831

832832
@Child private GetBaseClassNode getBaseClassNode;
833+
@Child private IsSameTypeNode isSameTypeNode;
833834
@Child private LookupAttributeInMRONode lookupSlotsNode;
834835
@Child private LookupAttributeInMRONode lookupNewNode;
835836
@Child private PyObjectSizeNode sizeNode;
@@ -842,21 +843,15 @@ public abstract static class CheckCompatibleForAssigmentNode extends PNodeWithCo
842843
public abstract boolean execute(VirtualFrame frame, Object oldBase, Object newBase);
843844

844845
@Specialization
845-
boolean isCompatible(VirtualFrame frame, Object oldBase, PythonAbstractClass newBase,
846+
boolean isCompatible(VirtualFrame frame, Object oldBase, Object newBase,
846847
@Cached BranchProfile errorSlotsBranch) {
847848
if (!compatibleForAssignment(frame, oldBase, newBase)) {
848849
errorSlotsBranch.enter();
849-
throw getRaiseNode().raise(TypeError, ErrorMessages.CLASS_ASIGMENT_S_LAYOUT_DIFFERS_FROM_S, getTypeName(newBase), getTypeName(oldBase));
850+
throw getRaiseNode().raise(TypeError, ErrorMessages.CLASS_ASSIGNMENT_S_LAYOUT_DIFFERS_FROM_S, getTypeName(newBase), getTypeName(oldBase));
850851
}
851852
return true;
852853
}
853854

854-
@Specialization
855-
boolean isCompatible(VirtualFrame frame, Object oldBase, PythonBuiltinClassType newBase,
856-
@Cached BranchProfile errorSlotsBranch) {
857-
return isCompatible(frame, oldBase, PythonContext.get(this).getCore().lookupType(newBase), errorSlotsBranch);
858-
}
859-
860855
/**
861856
* Aims to get as close as possible to typeobject.compatible_for_assignment().
862857
*/
@@ -876,7 +871,7 @@ private boolean compatibleForAssignment(VirtualFrame frame, Object oldB, Object
876871
oldParent = getBaseClassNode().execute(oldBase);
877872
}
878873

879-
return newBase == oldBase || (newParent == oldParent && sameSlotsAdded(frame, newBase, oldBase));
874+
return getIsSameTypeNode().execute(newBase, oldBase) || (getIsSameTypeNode().execute(newParent, oldParent) && sameSlotsAdded(frame, newBase, oldBase));
880875
}
881876

882877
/**
@@ -920,7 +915,7 @@ private boolean compatibleWithBase(VirtualFrame frame, Object child, Object pare
920915

921916
private boolean sameSlotsAdded(VirtualFrame frame, Object a, Object b) {
922917
// !(a->tp_flags & Py_TPFLAGS_HEAPTYPE) || !(b->tp_flags & Py_TPFLAGS_HEAPTYPE))
923-
if (a instanceof PythonBuiltinClass || b instanceof PythonBuiltinClass) {
918+
if (PGuards.isKindOfBuiltinClass(a) || PGuards.isKindOfBuiltinClass(b)) {
924919
return false;
925920
}
926921
Object aSlots = getSlotsFromType(a);
@@ -955,6 +950,14 @@ private GetBaseClassNode getBaseClassNode() {
955950
return getBaseClassNode;
956951
}
957952

953+
private IsSameTypeNode getIsSameTypeNode() {
954+
if (isSameTypeNode == null) {
955+
CompilerDirectives.transferToInterpreterAndInvalidate();
956+
isSameTypeNode = insert(IsSameTypeNode.create());
957+
}
958+
return isSameTypeNode;
959+
}
960+
958961
private String getTypeName(Object clazz) {
959962
if (getTypeNameNode == null) {
960963
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -1212,6 +1215,10 @@ boolean doOther(@SuppressWarnings("unused") Object left, @SuppressWarnings("unus
12121215
return false;
12131216
}
12141217

1218+
public static IsSameTypeNode create() {
1219+
return IsSameTypeNodeGen.create();
1220+
}
1221+
12151222
public static IsSameTypeNode getUncached() {
12161223
return IsSameTypeNodeGen.getUncached();
12171224
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
* report they are unequal to themselves (i.e. {@code NaN}).
7979
*/
8080
public abstract class PyObjectRichCompareBool {
81+
@SuppressWarnings("unused")
8182
protected static abstract class ComparisonBaseNode extends PNodeWithContext {
8283
public abstract boolean execute(Frame frame, Object a, Object b);
8384

@@ -290,7 +291,7 @@ boolean doGeneric(VirtualFrame frame, Object a, Object b,
290291
return doDefault(raiseNode, a, b);
291292
}
292293

293-
private Object lookupMethodIgnoreDescriptorError(VirtualFrame frame, LookupSpecialMethodSlotNode lookupMethod, Object aType, Object a) {
294+
private static Object lookupMethodIgnoreDescriptorError(VirtualFrame frame, LookupSpecialMethodSlotNode lookupMethod, Object aType, Object a) {
294295
try {
295296
return lookupMethod.execute(frame, aType, a);
296297
} catch (PException e) {
@@ -409,6 +410,7 @@ protected boolean identityComparisonResult() {
409410
}
410411

411412
@Override
413+
@SuppressWarnings("unused")
412414
protected boolean doDefault(PRaiseNode raiseNode, Object a, Object b) {
413415
// Already compared for identity
414416
return true;
@@ -456,6 +458,7 @@ protected SpecialMethodSlot getReverseSlot() {
456458
}
457459

458460
@Override
461+
@SuppressWarnings("unused")
459462
protected boolean doDefault(PRaiseNode raiseNode, Object a, Object b) {
460463
throw raiseNode.raise(TypeError, ErrorMessages.NOT_SUPPORTED_BETWEEN_INSTANCES, "<", a, b);
461464
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,8 @@ public abstract class ErrorMessages {
181181
public static final String CATCHING_CLS_NOT_ALLOWED = "catching classes that do not inherit from BaseException is not allowed";
182182
public static final String CHARACTER_MAPPING_MUST_BE_IN_RANGE = "character mapping must be in range(0x%s)";
183183
public static final String CHARACTER_MAPPING_MUST_RETURN_INT_NONE_OR_STR = "character mapping must return integer, None or str";
184-
public static final String CHR_DOES_NOT_SUPPORT = "chr does not support PInt ";
185-
public static final String CLASS_ASIGMENT_S_LAYOUT_DIFFERS_FROM_S = "__class__ assignment: '%s' object layout differs from '%s'";
186-
public static final String CLASS_ASSIGMENT_ONLY_SUPPORTED_FOR_HEAP_TYPES_OR_MODTYPE_SUBCLASSES = "__class__ assignment only supported for heap types or ModuleType subclasses";
187-
public static final String CLASS_ASSIGMENT_ONLY_SUPPORTED_FOR_HEAP_TYPES_OR_MODTYPE_SUBCLASSES_NOT_P = "__class__ assignment only supported for heap types or ModuleType subclasses, not '%p'";
184+
public static final String CLASS_ASSIGNMENT_S_LAYOUT_DIFFERS_FROM_S = "__class__ assignment: '%s' object layout differs from '%s'";
185+
public static final String CLASS_ASSIGNMENT_ONLY_SUPPORTED_FOR_HEAP_TYPES_OR_MODTYPE_SUBCLASSES = "__class__ assignment only supported for heap types or ModuleType subclasses";
188186
public static final String CLASS_MUST_BE_SET_TO_CLASS = "__class__ must be set to a class, not '%p' object";
189187
public static final String MUST_BE_SET_TO_S_NOT_P = "%s must be set to a %s, not a '%p'";
190188
public static final String CLASSPATH_ARG_MUST_BE_STRING = "classpath argument %d must be string, not %p";

0 commit comments

Comments
 (0)