| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2699fdc commit 6d2f0bd
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | using System; | |
| 2 | 2 | using System.Reflection; | |
| 3 | + using System.Text; | ||
| 3 | 4 | ||
| 4 | 5 | namespace Python.Runtime | |
| 5 | 6 | { | |
@@ -93,7 +94,15 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info) | |||
| 93 | 94 | ||
| 94 | 95 | if (binding == null) | |
| 95 | 96 | { | |
| 96 | - Exceptions.SetError(Exceptions.TypeError, "no constructor matches given arguments"); | ||
| 97 | + var errorMessage = new StringBuilder("No constructor matches given arguments"); | ||
| 98 | + if (info != null && info.IsConstructor && info.DeclaringType != null) | ||
| 99 | + { | ||
| 100 | + errorMessage.Append(" for ").Append(info.DeclaringType.Name); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + errorMessage.Append(": "); | ||
| 104 | + AppendArgumentTypes(to: errorMessage, args); | ||
| 105 | + Exceptions.SetError(Exceptions.TypeError, errorMessage.ToString()); | ||
| 97 | 106 | return null; | |
| 98 | 107 | } | |
| 99 | 108 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -599,6 +599,40 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase i | |||
| 599 | 599 | return Invoke(inst, args, kw, info, null); | |
| 600 | 600 | } | |
| 601 | 601 | ||
| 602 | + protected static void AppendArgumentTypes(StringBuilder to, IntPtr args) | ||
| 603 | + { | ||
| 604 | + long argCount = Runtime.PyTuple_Size(args); | ||
| 605 | + to.Append("("); | ||
| 606 | + for (long argIndex = 0; argIndex < argCount; argIndex++) | ||
| 607 | + { | ||
| 608 | + var arg = Runtime.PyTuple_GetItem(args, argIndex); | ||
| 609 | + if (arg != IntPtr.Zero) | ||
| 610 | + { | ||
| 611 | + var type = Runtime.PyObject_Type(arg); | ||
| 612 | + if (type != IntPtr.Zero) | ||
| 613 | + { | ||
| 614 | + try | ||
| 615 | + { | ||
| 616 | + var description = Runtime.PyObject_Unicode(type); | ||
| 617 | + if (description != IntPtr.Zero) | ||
| 618 | + { | ||
| 619 | + to.Append(Runtime.GetManagedString(description)); | ||
| 620 | + Runtime.XDecref(description); | ||
| 621 | + } | ||
| 622 | + } | ||
| 623 | + finally | ||
| 624 | + { | ||
| 625 | + Runtime.XDecref(type); | ||
| 626 | + } | ||
| 627 | + } | ||
| 628 | + } | ||
| 629 | + | ||
| 630 | + if (argIndex + 1 < argCount) | ||
| 631 | + to.Append(", "); | ||
| 632 | + } | ||
| 633 | + to.Append(')'); | ||
| 634 | + } | ||
| 635 | + | ||
| 602 | 636 | internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, MethodInfo[] methodinfo) | |
| 603 | 637 | { | |
| 604 | 638 | Binding binding = Bind(inst, args, kw, info, methodinfo); | |
@@ -613,29 +647,8 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase i | |||
| 613 | 647 | value.Append($" for {methodinfo[0].Name}"); | |
| 614 | 648 | } | |
| 615 | 649 | ||
| 616 | - long argCount = Runtime.PyTuple_Size(args); | ||
| 617 | - value.Append(": ("); | ||
| 618 | - for(long argIndex = 0; argIndex < argCount; argIndex++) { | ||
| 619 | - var arg = Runtime.PyTuple_GetItem(args, argIndex); | ||
| 620 | - if (arg != IntPtr.Zero) { | ||
| 621 | - var type = Runtime.PyObject_Type(arg); | ||
| 622 | - if (type != IntPtr.Zero) { | ||
| 623 | - try { | ||
| 624 | - var description = Runtime.PyObject_Unicode(type); | ||
| 625 | - if (description != IntPtr.Zero) { | ||
| 626 | - value.Append(Runtime.GetManagedString(description)); | ||
| 627 | - Runtime.XDecref(description); | ||
| 628 | - } | ||
| 629 | - } finally { | ||
| 630 | - Runtime.XDecref(type); | ||
| 631 | - } | ||
| 632 | - } | ||
| 633 | - } | ||
| 634 | - | ||
| 635 | - if (argIndex + 1 < argCount) | ||
| 636 | - value.Append(", "); | ||
| 637 | - } | ||
| 638 | - value.Append(')'); | ||
| 650 | + value.Append(": "); | ||
| 651 | + AppendArgumentTypes(to: value, args); | ||
| 639 | 652 | Exceptions.SetError(Exceptions.TypeError, value.ToString()); | |
| 640 | 653 | return IntPtr.Zero; | |
| 641 | 654 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments