Skip to content

Commit 29c1f1c

Browse files
committed
make exception.__context__ writable
1 parent 863d208 commit 29c1f1c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,24 @@ public Object cause(PBaseException self, PBaseException value,
164164
}
165165
}
166166

167-
@Builtin(name = __CONTEXT__, minNumOfPositionalArgs = 1, isGetter = true)
167+
@Builtin(name = __CONTEXT__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true)
168168
@GenerateNodeFactory
169169
public abstract static class ContextNode extends PythonBuiltinNode {
170+
@Specialization(guards = "isNoValue(value)")
171+
public Object context(PBaseException self, @SuppressWarnings("unused") PNone value,
172+
@Cached("create()") ReadAttributeFromObjectNode readContext) {
173+
Object context = readContext.execute(self, __CONTEXT__);
174+
if (context == PNone.NO_VALUE) {
175+
return PNone.NONE;
176+
} else {
177+
return context;
178+
}
179+
}
170180

171181
@Specialization
172-
public Object context(@SuppressWarnings("unused") PBaseException self) {
182+
public Object context(PBaseException self, PBaseException value,
183+
@Cached("create()") WriteAttributeToObjectNode writeContext) {
184+
writeContext.execute(self, __CONTEXT__, value);
173185
return PNone.NONE;
174186
}
175187
}

0 commit comments

Comments
 (0)