Skip to content

Commit 0131038

Browse files
committed
add __get__ to PyBuiltinMethodSet so it functions properly as a descriptor
1 parent c565348 commit 0131038

5 files changed

Lines changed: 24 additions & 8 deletions

File tree

src/com/ziclix/python/sql/PyConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ boolean contains(PyStatement statement) {
461461

462462
class ConnectionFunc extends PyBuiltinMethodSet {
463463
ConnectionFunc(String name, int index, int minargs, int maxargs, String doc) {
464-
super(name, index, minargs, maxargs, doc);
464+
super(name, index, minargs, maxargs, doc, PyConnection.class);
465465
}
466466

467467
public PyObject __call__() {

src/com/ziclix/python/sql/PyCursor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,10 +875,10 @@ public static boolean isSeqSeq(PyObject object) {
875875

876876
class CursorFunc extends PyBuiltinMethodSet {
877877
CursorFunc(String name, int index, int argcount, String doc) {
878-
super(name, index, argcount, argcount, doc);
878+
this(name, index, argcount, argcount, doc);
879879
}
880880
CursorFunc(String name, int index, int minargs, int maxargs, String doc) {
881-
super(name, index, minargs, maxargs, doc);
881+
super(name, index, minargs, maxargs, doc, PyCursor.class);
882882
}
883883

884884
public PyObject __call__() {

src/com/ziclix/python/sql/PyExtendedCursor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,11 @@ protected String getMetaDataName(PyObject name) {
489489
class ExtendedCursorFunc extends PyBuiltinMethodSet {
490490

491491
ExtendedCursorFunc(String name, int index, int argcount, String doc) {
492-
super(name, index, argcount, argcount, doc);
492+
this(name, index, argcount, argcount, doc);
493493
}
494494

495495
ExtendedCursorFunc(String name, int index, int minargs, int maxargs, String doc) {
496-
super(name, index, minargs, maxargs, doc);
496+
super(name, index, minargs, maxargs, doc, PyExtendedCursor.class);
497497
}
498498

499499
public PyObject __call__() {

src/com/ziclix/python/sql/util/BCP.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ protected PyObject bcp(String fromTable, String where, PyObject params, PyObject
212212
class BCPFunc extends PyBuiltinMethodSet {
213213

214214
BCPFunc(String name, int index, int argcount, String doc) {
215-
super(name, index, argcount, argcount, doc);
215+
this(name, index, argcount, argcount, doc);
216216
}
217217

218218
BCPFunc(String name, int index, int minargs, int maxargs, String doc) {
219-
super(name, index, minargs, maxargs, doc);
219+
super(name, index, minargs, maxargs, doc, BCP.class);
220220
}
221221

222222
/**

src/org/python/core/PyBuiltinMethodSet.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,22 @@ public PyBuiltinMethodSet(String name,
77
int index,
88
int minargs,
99
int maxargs,
10-
String doc) {
10+
String doc,
11+
Class type) {
1112
super(name, index, minargs, maxargs, doc);
13+
this.type = type;
14+
}
15+
16+
public PyObject __get__(PyObject obj, PyObject type) {
17+
if(obj != null) {
18+
if(this.type.isAssignableFrom(obj.getClass())) {
19+
return bind(obj);
20+
} else {
21+
throw Py.TypeError("descriptor '" + info.getName() + "' for '" + PyType.fromClass(this.type)
22+
+ "' objects doesn't apply to '" + obj.getType() + "' object");
23+
}
24+
}
25+
return this;
1226
}
1327

1428
public PyBuiltinFunction bind(PyObject bindTo) {
@@ -34,5 +48,7 @@ public String toString(){
3448
return "<built-in method "+info.getName()+">";
3549
}
3650

51+
private Class type;
52+
3753
protected PyObject __self__ = Py.None;
3854
}

0 commit comments

Comments
 (0)