Skip to content

Commit 453310c

Browse files
committed
allow deletion of function __module__ attribute
1 parent f4b351b commit 453310c

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ Object getGlobals(Object self) {
180180
}
181181
}
182182

183-
@Builtin(name = __MODULE__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true)
183+
@Builtin(name = __MODULE__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true, allowsDelete = true)
184184
@GenerateNodeFactory
185185
abstract static class GetModuleNode extends PythonBuiltinNode {
186186
@Specialization(guards = {"!isBuiltinFunction(self)", "isNoValue(none)"})
187187
Object getModule(VirtualFrame frame, PFunction self, @SuppressWarnings("unused") PNone none,
188188
@Cached("create()") ReadAttributeFromObjectNode readObject,
189189
@Cached("create()") GetItemNode getItem,
190-
@Cached("create()") WriteAttributeToObjectNode writeObject) {
190+
@Cached.Shared("writeObject") @Cached("create()") WriteAttributeToObjectNode writeObject) {
191191
Object module = readObject.execute(self, __MODULE__);
192192
if (module == PNone.NO_VALUE) {
193193
CompilerDirectives.transferToInterpreter();
@@ -202,9 +202,16 @@ Object getModule(VirtualFrame frame, PFunction self, @SuppressWarnings("unused")
202202
return module;
203203
}
204204

205-
@Specialization(guards = {"!isBuiltinFunction(self)", "!isNoValue(value)"})
206-
Object getModule(PFunction self, Object value,
207-
@Cached("create()") WriteAttributeToObjectNode writeObject) {
205+
@Specialization(guards = {"!isBuiltinFunction(self)", "isDeleteMarker(value)"})
206+
Object delModule(PFunction self, @SuppressWarnings("unused") Object value,
207+
@Cached.Shared("writeObject") @Cached("create()") WriteAttributeToObjectNode writeObject) {
208+
writeObject.execute(self, __MODULE__, PNone.NONE);
209+
return PNone.NONE;
210+
}
211+
212+
@Specialization(guards = {"!isBuiltinFunction(self)", "!isNoValue(value)", "!isDeleteMarker(value)"})
213+
Object setModule(PFunction self, Object value,
214+
@Cached.Shared("writeObject") @Cached("create()") WriteAttributeToObjectNode writeObject) {
208215
writeObject.execute(self, __MODULE__, value);
209216
return PNone.NONE;
210217
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/KeywordArgumentsNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ PKeyword[] doDict(PKeyword[] arguments, PDict starargs,
9595

9696
protected boolean isNonMapping(PKeyword[] arguments, Object starargs) {
9797
return (arguments.length == 0 && PGuards.isPNone(starargs)) ||
98-
(!PGuards.isDict(starargs) && !PGuards.isPNone(starargs));
98+
(!PGuards.isDict(starargs) && !PGuards.isPNone(starargs));
9999
}
100100

101101
@Specialization(guards = "arguments.length > 0")

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/positional/ExecutePositionalStarargsNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import com.oracle.graal.python.runtime.PythonOptions;
6262
import com.oracle.graal.python.runtime.exception.PException;
6363
import com.oracle.graal.python.runtime.exception.PythonErrorType;
64-
import com.oracle.graal.python.util.PythonUtils;
6564
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6665
import com.oracle.truffle.api.dsl.Cached;
6766
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -123,7 +122,7 @@ static Object[] doSet(PSet starargs,
123122

124123
@Specialization
125124
static Object[] doNone(PNone none,
126-
@Cached PRaiseNode raise) {
125+
@Cached PRaiseNode raise) {
127126
throw raise.raise(PythonErrorType.TypeError, ErrorMessages.ARG_AFTER_MUST_BE_ITERABLE, none);
128127
}
129128

0 commit comments

Comments
 (0)