use of org.cafebabepy.runtime.object.proxy.PyMethodTypeObject in project cafebabepy by cafebabepy.
the class PyObjectType method __getattribute__.
@DefinePyFunction(name = __getattribute__)
public PyObject __getattribute__(PyObject self, PyObject name) {
String n = name.toJava(String.class);
Optional<PyObject> resultOpt = self.getScope().get(n);
if (resultOpt.isPresent()) {
return resultOpt.get();
}
boolean isParent = false;
resultOpt = getFromTypes(self, n);
if (!resultOpt.isPresent()) {
resultOpt = getFromType(self, n);
if (!resultOpt.isPresent()) {
resultOpt = getFromParent(self, n);
if (!resultOpt.isPresent()) {
if (self.isModule()) {
throw this.runtime.newRaiseException("builtins.AttributeError", "module '" + self.getName() + "' has no attribute '" + name + "'");
} else if (self.isType()) {
throw this.runtime.newRaiseException("builtins.AttributeError", "type object '" + self.getName() + "' has no attribute '" + name + "'");
} else {
throw this.runtime.newRaiseException("builtins.AttributeError", "'" + self.getName() + "' object has no attribute '" + name + "'");
}
} else {
// Module
isParent = true;
}
}
}
PyObject result = resultOpt.get();
if (!result.isCallable() || isParent) {
return result;
} else {
synchronized (this) {
// if (this.methodMap == null) {
// this.methodMap = new LinkedHashMap<>();
// }
// PyObject method = this.methodMap.get(name);
PyObject method = null;
if (method == null) {
// method = newPyObject("types.MethodType", result, object);
method = new PyMethodTypeObject(this.runtime, self, result);
// this.methodMap.put(name, method);
}
return method;
}
}
}
Aggregations