org.python.core.PyClassMethodDescr Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jython-standalone Show documentation
Show all versions of jython-standalone Show documentation
Jython is an implementation of the high-level, dynamic, object-oriented
language Python written in 100% Pure Java, and seamlessly integrated with
the Java platform. It thus allows you to run Python on any Java platform.
package org.python.core;
import org.python.expose.ExposedMethod;
import org.python.expose.ExposedType;
@ExposedType(name = "classmethod_descriptor", isBaseType = false)
public class PyClassMethodDescr extends PyMethodDescr {
public static final PyType TYPE = PyType.fromClass(PyClassMethodDescr.class);
PyClassMethodDescr(PyType t, PyBuiltinCallable meth) {
super(t, meth);
}
public PyObject __get__(PyObject obj, PyObject type) {
return classmethod_descriptor___get__(obj, type);
}
@ExposedMethod(defaults = "null")
public PyObject classmethod_descriptor___get__(PyObject obj, PyObject type) {
if (type == null || type == Py.None) {
if (obj != null) {
type = obj.getType();
} else {
throw Py.TypeError(String.format("descriptor '%s' for type '%s' needs either an "
+ " object or a type", name, dtype.fastGetName()));
}
} else if (!(type instanceof PyType)) {
throw Py.TypeError(String.format("descriptor '%s' for type '%s' needs a type, not a"
+ " '%s' as arg 2", name, dtype.fastGetName(),
type.getType().fastGetName()));
}
checkGetterType((PyType)type);
return meth.bind(type);
}
}