-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathPyDescriptor.java
More file actions
38 lines (30 loc) · 1.13 KB
/
PyDescriptor.java
File metadata and controls
38 lines (30 loc) · 1.13 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
package org.python.core;
public abstract class PyDescriptor extends PyObject implements Traverseproc {
protected PyType dtype;
protected String name;
protected void checkCallerType(PyType type) {
if (type == dtype || type.isSubType(dtype)) {
return;
}
String msg = String.format("descriptor '%s' requires a '%s' object but received a '%s'",
name, dtype.fastGetName(), type.fastGetName());
throw Py.TypeError(msg);
}
protected void checkGetterType(PyType type) {
if (type == dtype || type.isSubType(dtype)) {
return;
}
String msg = String.format("descriptor '%s' for '%s' objects doesn't apply to '%s' object",
name, dtype.fastGetName(), type.fastGetName());
throw Py.TypeError(msg);
}
/* Traverseproc implementation */
@Override
public int traverse(Visitproc visit, Object arg) {
return dtype != null ? visit.visit(dtype, arg) : 0;
}
@Override
public boolean refersDirectlyTo(PyObject ob) {
return ob == dtype;
}
}