-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathPyClassMethodDescr.java
More file actions
46 lines (39 loc) · 1.58 KB
/
PyClassMethodDescr.java
File metadata and controls
46 lines (39 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Copyright (c) Jython Developers */
package org.python.core;
import org.python.expose.ExposedGet;
import org.python.expose.ExposedMethod;
import org.python.expose.ExposedType;
@Untraversable
@ExposedType(name = "classmethod_descriptor", isBaseType = false)
public class PyClassMethodDescr extends PyMethodDescr {
public static final PyType TYPE = PyType.fromClass(PyClassMethodDescr.class);
PyClassMethodDescr(PyType type, PyBuiltinCallable meth) {
super(type, meth);
}
@Override
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);
}
@Override
@ExposedGet(name = "__doc__")
public String getDoc() {
return super.getDoc();
}
}