8000 Selecting overloaded methods with unsigned integer argument fails · Issue #283 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Selecting overloaded methods with unsigned integer argument fails #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
makalu79 opened this issue Nov 4, 2016 · 2 comments
Open

Selecting overloaded methods with unsigned integer argument fails #283

makalu79 opened this issue Nov 4, 2016 · 2 comments

Comments

@makalu79
Copy link
makalu79 commented Nov 4, 2016

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)

@den-run-ai
Copy link
Contributor

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 notifications@github.com wrote:

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


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#283, or mute the thread
https://github.com/notifications/unsubscribe-auth/AHgZ5c7Y_eFaESTrZJdyTYKQ8UZdFHVNks5q6y2tgaJpZM4Kpg9E
.

@makalu79
Copy link
Author

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) ||

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0