Skip to content

Commit b00a2d3

Browse files
committed
PBaseException: add missing with_traceback builtin method
1 parent 74a4adc commit b00a2d3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/BaseExceptionBuiltins.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.oracle.graal.python.builtins.PythonBuiltins;
3737
import com.oracle.graal.python.builtins.objects.PNone;
3838
import com.oracle.graal.python.builtins.objects.list.PList;
39+
import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
3940
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
4041
import com.oracle.graal.python.nodes.expression.CastToListNode;
4142
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
@@ -156,4 +157,21 @@ public Object traceback(PBaseException self) {
156157
return self.getTraceback(factory());
157158
}
158159
}
160+
161+
@Builtin(name = "with_traceback", fixedNumOfArguments = 2)
162+
@GenerateNodeFactory
163+
public abstract static class WithTracebackNode extends PythonBuiltinNode {
164+
165+
@Specialization
166+
public Object withTraceback(PBaseException self, @SuppressWarnings("unused") PNone tb) {
167+
self.clearTraceback();
168+
return PNone.NONE;
169+
}
170+
171+
@Specialization
172+
public Object withTraceback(PBaseException self, PTraceback tb) {
173+
self.setTraceback(tb);
174+
return PNone.NONE;
175+
}
176+
}
159177
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/PBaseException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ public void setTraceback(PTraceback traceback) {
114114
this.traceback = traceback.getException().traceback;
115115
}
116116

117+
public void clearTraceback() {
118+
this.traceback = new PTraceback[0];
119+
}
120+
117121
/**
118122
* Can be null in case of lazily formatted arguments.
119123
*/

0 commit comments

Comments
 (0)