FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Don't mask exceptions in managed constructors · pythonnet/pythonnet@eb27f97 · GitHub

Commit eb27f97

Browse files
Barton Cline
committed
Don't mask exceptions in managed constructors
Author: Alexey Borzenkov (snaury@gmail.com) Date: Thu Dec 17 09:34:23 2009 +0300
1 parent b165605 commit eb27f97

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

‎pythonnet/src/runtime/classobject.cs‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) {
106106

107107
Object obj = self.binder.InvokeRaw(IntPtr.Zero, args, kw);
108108
if (obj == null) {
109-
// It is possible for __new__ to be invoked on construction
110-
// of a Python subclass of a managed class, so args may
111-
// reflect more args than are required to instantiate the
112-
// class. So if we cant find a ctor that matches, we'll see
113-
// if there is a default constructor and, if so, assume that
114-
// any extra args are intended for the subclass' __init__.
115-
116-
IntPtr eargs = Runtime.PyTuple_New(0);
117-
obj = self.binder.InvokeRaw(IntPtr.Zero, eargs, kw);
118-
Runtime.Decref(eargs);
119-
if (obj == null) {
120-
return IntPtr.Zero;
121-
}
109+
return IntPtr.Zero;
122110
}
123111

124112
return CLRObject.GetInstHandle(obj, tp);

‎pythonnet/src/runtime/constructorbinder.cs‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,23 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw,
4343
Object result;
4444

4545
if (binding == null) {
46-
Exceptions.SetError(Exceptions.TypeError,
47-
"no constructor matches given arguments"
48-
);
49-
return null;
46+
// It is possible for __new__ to be invoked on construction
47+
// of a Python subclass of a managed class, so args may
48+
// reflect more args than are required to instantiate the
49+
// class. So if we cant find a ctor that matches, we'll see
50+
// if there is a default constructor and, if so, assume that
51+
// any extra args are intended for the subclass' __init__.
52+
53+
IntPtr eargs = Runtime.PyTuple_New(0);
54+
binding = this.Bind(inst, eargs, kw);
55+
Runtime.Decref(eargs);
56+
57+
if (binding == null) {
58+
Exceptions.SetError(Exceptions.TypeError,
59+
"no constructor matches given arguments"
60+
);
61+
return null;
62+
}
5063
}
5164

5265
// Object construction is presumed to be non-blocking and fast

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL