You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Selecting overloaded methods with unsigned integer argument fails #283
When trying to invoke a .NET method with a unsigned integer argument, it fails with "No method matches given arguments", if there is another method signature with the same name. To reproduce, use the class:
public class Class1
{
public string MethodWithOverloading(UInt16 aParam1)
{
return string.Format("MethodWithOverloading(int {0})", aParam1);
}
public string MethodWithOverloading(string aParam2)
{
return string.Format("MethodWithOverloading(string {0})", aParam2);
}
public string MethodWithOverloading(UInt16 aParam1, string aParam2)
{
return string.Format("MethodWithOverloading(int {0}, string {1})", aParam1, aParam2);
}
}
Then called from python with:
c = Class1()
print c.MethodWithOverloading('test')
print c.MethodWithOverloading(42)
print c.MethodWithOverloading(42, 'test')
line 2 works fine, but lines 3 and 4 fail with TypeError: No method matches given arguments (using 2.1.0)
When trying to invoke a .NET method with a unsigned integer argument, it
fails with "No method matches given arguments", if there is another method
signature with the same name. To reproduce, use the class:
public class Class1
{
public string MethodWithOverloading(UInt16 aParam1)
{
return string.Format("MethodWithOverloading(int {0})", aParam1);
}
Yes, that would be possible. But when using "3rd party" assembly, that would mean to write wrappers around every method including range checking. Of course, if the .NET method has overloaded signature which just differs by an argument being either unsigned or signet integer, we're out of luck! But the strage thing is, the exact same code worked in pythonnet 2.0.0. I tried to attach a patch file for pythonnet 2.1.0 version of runtime/converter.cs which solved the problem for me, didn't work, so pardon me for pasting it into the comments below.
--- C:/work/Test/pythonnet-2.1.0/src/runtime/converter (2).cs Do Nov 10 08:30:16 2016
+++ C:/work/Test/pythonnet-2.1.0/src/runtime/converter.cs Do Nov 10 10:20:18 2016
@@ -35,6 +35,9 @@ namespace Python.Runtime {
static Type int16Type;
static Type int32Type;
static Type int64Type;
+ static Type uint16Type;
+ static Type uint32Type;
+ static Type uint64Type;
static Type flagsType;
static Type boolType;
static Type typeType;
@@ -46,6 +49,9 @@ namespace Python.Runtime {
int16Type = typeof(Int16);
int32Type = typeof(Int32);
int64Type = typeof(Int64);
+ uint16Type = typeof(UInt16);
+ uint32Type = typeof(UInt32);
+ uint64Type = typeof(UInt64);
singleType = typeof(Single);
doubleType = typeof(Double);
decimalType = typeof(Decimal);
@@ -92,10 +98,13 @@ namespace Python.Runtime {
}
#endif
else if ((op == int16Type) ||
- (op == int32Type)) {
+ (op == int32Type) ||
+ (op == uint16Type) ||
+ (op == uint32Type)) {
return Runtime.PyIntType;
}
- else if (op == int64Type) {
+ else if ((op == int64Type) ||
+ (op == uint64Type)) {
return Runtime.PyLongType;
}
else if ((op == doubleType) ||
Activity
den-run-ai commentedon Nov 4, 2016
Can't you convert to .NET type(s) before passing in? There is no built-in
equivalent of unsigned integer in Python.
On Fri, Nov 4, 2016, 8:05 AM makalu79 [email protected] wrote:
makalu79 commentedon Nov 10, 2016
Yes, that would be possible. But when using "3rd party" assembly, that would mean to write wrappers around every method including range checking. Of course, if the .NET method has overloaded signature which just differs by an argument being either unsigned or signet integer, we're out of luck! But the strage thing is, the exact same code worked in pythonnet 2.0.0. I tried to attach a patch file for pythonnet 2.1.0 version of runtime/converter.cs which solved the problem for me, didn't work, so pardon me for pasting it into the comments below.