Skip to content

Commit bb6492e

Browse files
committed
Allow classmethods to be exposed on builtin types using @ExposedClassMethod and
expose dict with its fromkeys classmethod using that. Expose defaultdict.
1 parent d07e181 commit bb6492e

27 files changed

+526
-1049
lines changed

CoreExposed.includes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ org/python/core/PyBoolean.class
44
org/python/core/PyBuiltinFunction.class
55
org/python/core/PyClassMethod.class
66
org/python/core/PyComplex.class
7+
org/python/core/PyDictionary.class
78
org/python/core/PyEnumerate.class
89
org/python/core/PyFile.class
910
org/python/core/PyFloat.class
@@ -15,6 +16,7 @@ org/python/core/PyObject.class
1516
org/python/core/PyString.class
1617
org/python/core/PyType.class
1718
org/python/core/PyUnicode.class
19+
org/python/modules/collections/PyDefaultDict.class
1820
org/python/modules/collections/PyDeque.class
1921
org/python/modules/time/PyTimeTuple.class
2022
org/python/modules/zipimport/zipimporter.class

src/org/python/core/BytecodeLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
9999
throw new ClassNotFoundException(name);
100100
}
101101

102-
public Class loadClassFromBytes(String name, byte[] data) {
103-
Class c = defineClass(name, data, 0, data.length, getClass().getProtectionDomain());
102+
public Class<?> loadClassFromBytes(String name, byte[] data) {
103+
Class<?> c = defineClass(name, data, 0, data.length, getClass().getProtectionDomain());
104104
resolveClass(c);
105105
Compiler.compileClass(c);
106106
return c;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.python.core;
2+
3+
4+
/**
5+
* A builtin classmethod with a restricted number of arguments.
6+
*/
7+
public abstract class PyBuiltinClassMethodNarrow extends PyBuiltinMethodNarrow {
8+
9+
protected PyBuiltinClassMethodNarrow(String name, int minArgs, int maxArgs) {
10+
super(name, minArgs, maxArgs);
11+
}
12+
13+
protected PyBuiltinClassMethodNarrow(PyObject self, Info info) {
14+
super(self, info);
15+
}
16+
17+
protected PyBuiltinClassMethodNarrow(PyType type, PyObject self, Info info) {
18+
super(type, self, info);
19+
}
20+
21+
public PyMethodDescr makeDescriptor(PyType t) {
22+
return new PyClassMethodDescr(t, this);
23+
}
24+
25+
26+
}

src/org/python/core/PyBuiltinMethod.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ protected PyBuiltinMethod(String name) {
2121
public PyObject getSelf(){
2222
return self;
2323
}
24+
25+
public PyMethodDescr makeDescriptor(PyType t) {
26+
return new PyMethodDescr(t, this);
27+
}
2428

2529
protected PyObject self;
2630
}

src/org/python/core/PyClassMethodDescr.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
public class PyClassMethodDescr extends PyMethodDescr {
44

5+
PyClassMethodDescr(PyType t, PyBuiltinFunction meth) {
6+
super(t, meth);
7+
}
8+
59
public PyClassMethodDescr(String name,
610
Class c,
711
int minargs,

0 commit comments

Comments
 (0)