Skip to content

Commit 442e507

Browse files
committed
MethodBuiltins: implement __getattribute__ builtin
1 parent e4d6980 commit 442e507

File tree

1 file changed

+13
-5
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method

1 file changed

+13
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__DICT__;
3232
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__FUNC__;
3333
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__KWDEFAULTS__;
34-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTR__;
34+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTRIBUTE__;
3535
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GET__;
3636
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REDUCE__;
3737
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REPR__;
@@ -57,6 +57,8 @@
5757
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
5858
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
5959
import com.oracle.graal.python.nodes.object.GetLazyClassNode;
60+
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
61+
import com.oracle.graal.python.runtime.exception.PException;
6062
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6163
import com.oracle.truffle.api.dsl.Cached;
6264
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -106,13 +108,19 @@ protected Object doIt(VirtualFrame frame, PMethod self,
106108
}
107109
}
108110

109-
@Builtin(name = __GETATTR__, minNumOfPositionalArgs = 2)
111+
@Builtin(name = __GETATTRIBUTE__, minNumOfPositionalArgs = 2)
110112
@GenerateNodeFactory
111-
public abstract static class GetattrNode extends PythonBuiltinNode {
113+
public abstract static class GetattributeNode extends PythonBuiltinNode {
112114
@Specialization
113115
protected Object doIt(VirtualFrame frame, PMethod self, Object key,
114-
@Cached("create()") ObjectBuiltins.GetAttributeNode objectGetattrNode) {
115-
return objectGetattrNode.execute(frame, self.getFunction(), key);
116+
@Cached("create()") ObjectBuiltins.GetAttributeNode objectGetattrNode,
117+
@Cached("create()") IsBuiltinClassProfile errorProfile) {
118+
try {
119+
return objectGetattrNode.execute(frame, self, key);
120+
} catch (PException e) {
121+
e.expectAttributeError(errorProfile);
122+
return objectGetattrNode.execute(frame, self.getFunction(), key);
123+
}
116124
}
117125
}
118126

0 commit comments

Comments
 (0)