Discussion:
[Python.NET] issue disambiguating overloaded method that takes an array
Adrian Perez
2011-05-17 01:29:36 UTC
Permalink
Hello everyone,

This is probably a total n00b question, but I've been using pythonnet in our toolchain to communicate with a private c# assembly for months now without ever running into a problem I couldn't eventually figure out. This one has me totally stumped, and I'm hoping something obvious will jump out at experienced eyes.

(I did a find/replace for secrecy, besides silly names these are the raw results I get back)
accessor= MyCompany.SomeNamespace.SomeTypeArrayAccessor
accessor.WriteByte.__overloads__
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Byte[])
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Byte[], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, System.Collections.Generic.IEnumerable`1[System.Byte], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Int32, System.Collections.Generic.IEnumerable`1[System.Byte], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Int32, Byte[], Int32 ByRef)
desired_method= accessor.WriteByte.__overloads__[MyCompany.SomeNamespace.SomeType, System.Array[System.Byte]]
arg_a= ...
arg_b= ...
type(arg_a)
<class 'MyCompany.SomeNamespace.SomeType'>
type(arg_b)
<class 'System.Byte[]'>
result= desired_method(arg_a, arg_b)
Traceback (most recent call last):
File "<string>", line 1, in <fragment>
TypeError: No method matches given arguments

Does anyone see the obvious thing I'm doing wrong? Disambiguating can be a pain but I've done it before for other methods and have never had such an impossible time getting the correct method called.

Thanks,

Adrian Perez
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Barton
2011-05-17 07:38:21 UTC
Permalink
Received: from localhost (HELO mail.python.org) (127.0.0.1)
by albatross.python.org with SMTP; 17 May 2011 09:38:30 +0200
Received: from nm22-vm0.bullet.mail.sp2.yahoo.com
(nm22-vm0.bullet.mail.sp2.yahoo.com [98.139.91.222])
by mail.python.org (Postfix) with SMTP
for <pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org>; Tue, 17 May 2011 09:38:28 +0200 (CEST)
Received: from [98.139.91.65] by nm22.bullet.mail.sp2.yahoo.com with NNFMP;
17 May 2011 07:38:21 -0000
Received: from [98.139.91.19] by tm5.bullet.mail.sp2.yahoo.com with NNFMP;
17 May 2011 07:38:21 -0000
Received: from [127.0.0.1] by omp1019.mail.sp2.yahoo.com with NNFMP;
17 May 2011 07:38:21 -0000
X-Yahoo-Newman-Id: 192283.38098.bm-***@public.gmane.org
Received: (qmail 49717 invoked from network); 17 May 2011 07:38:20 -0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024;
t=1305617900; bh=w3EQ5VdOSO2e3nleqpOcT83oTpjRdtyoN7ZIjThRHh4=;
h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding;
b=WzGba1+uT+p4ai3BbcXkUAWo8WXOLnuyimlnOUciQEpbHirHBWDDmc4STkwKKk1IB1LKZSCr4GI2jDAxcHdA5mJArAq64uJEItnrMK+QumZVQkxkPMXYcAyLTMhFM4eLIx33zBOL6/CjA2dud+jrNil320UMyZriNjcF9vGc29M=
Received: from [192.168.0.102] (barton-ngaorLX6cNskx0PYSKx/***@public.gmane.org with plain)
by smtp113.biz.mail.mud.yahoo.com with SMTP;
17 May 2011 00:38:20 -0700 PDT
X-Yahoo-SMTP: U71VqzGswBDO9FrcuPHuUtnn.9UhQIfe
X-YMail-OSG: WHjg3doVM1n7U9da.Nv1LXbDo1Mwi6GeKA27wiFyGsGDKWA
7s5rFgJF8JH62R67FsZQ_1D1WE3YcPYIqWQOwNOKNfhJHAiKw9MfJhuBb2ET
Iedx8BV4u52a1AdOmocZMCMC4QUGADNqChV44NJ84d8tZ05Uun1HGb9L_Lem
CARiZw2odz5Z5WShwYBs1.iGZoWFb9VrDVRMiSFH5rkqb7t6iTwOM6vKdrWQ
Z2Ss9ysHNsRnD31Pnx30UG30g1nEEYcg6xNYoajke1mwN7OJvVHhJF_.uoFe
b5XlGPLGB.C7X71Me8YcPqorgOcEpxEy4x1ZdO8pO8NN8kkHsZHYmJAk.nO4
8QzOei7Fo06ogtGW1F7rdQHaLabRoFmIoE6RR_Ta210C.sPHwKJPfr6vsewq
9B5L8nLdTiuO9CmZZpmSzE8OfMQ--
X-Yahoo-Newman-Property: ymail-3
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US;
rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10
In-Reply-To: <D7F4D9E414140644BF099886C28C6636798B2C9522-th/oG/DOLDocgAu2LIQXjdMlmXhkfIO8uOMsETyM3/***@public.gmane.org>
X-BeenThere: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
X-Mailman-Version: 2.1.12
Precedence: list
List-Id: "A list for users and developers of Python for .NET"
<pythondotnet.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/options/pythondotnet>,
<mailto:pythondotnet-request-+ZN9ApsXKcEdnm+***@public.gmane.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/pythondotnet>
List-Post: <mailto:pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org>
List-Help: <mailto:pythondotnet-request-+ZN9ApsXKcEdnm+***@public.gmane.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/pythondotnet>,
<mailto:pythondotnet-request-+ZN9ApsXKcEdnm+***@public.gmane.org?subject=subscribe>
Sender: pythondotnet-bounces+gcpd-pythondotnet=m.gmane.org-+ZN9ApsXKcEdnm+***@public.gmane.org
Errors-To: pythondotnet-bounces+gcpd-pythondotnet=m.gmane.org-+ZN9ApsXKcEdnm+***@public.gmane.org
Archived-At: <http://permalink.gmane.org/gmane.comp.python.dotnet/1109>


def TestCharArray():
from System import Array
charArrType = Array[Char]
##arrType = charArrType('hello')
##for char in arrType:
## print char,
## Also works on instances of the type! ##
strCharArr = s.__overloads__[charArrType]
s = strCharArr(list('hello'))
print s
Post by Adrian Perez
Hello everyone,
This is probably a total n00b question, but I've been using pythonnet in our toolchain to communicate with a private c# assembly for months now without ever running into a problem I couldn't eventually figure out. This one has me totally stumped, and I'm hoping something obvious will jump out at experienced eyes.
(I did a find/replace for secrecy, besides silly names these are the raw results I get back)
accessor= MyCompany.SomeNamespace.SomeTypeArrayAccessor
accessor.WriteByte.__overloads__
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Byte[])
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Byte[], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, System.Collections.Generic.IEnumerable`1[System.Byte], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Int32, System.Collections.Generic.IEnumerable`1[System.Byte], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Int32, Byte[], Int32 ByRef)
desired_method= accessor.WriteByte.__overloads__[MyCompany.SomeNamespace.SomeType, System.Array[System.Byte]]
arg_a= ...
arg_b= ...
type(arg_a)
<class 'MyCompany.SomeNamespace.SomeType'>
type(arg_b)
<class 'System.Byte[]'>
result= desired_method(arg_a, arg_b)
File "<string>", line 1, in<fragment>
TypeError: No method matches given arguments
Does anyone see the obvious thing I'm doing wrong? Disambiguating can be a pain but I've done it before for other methods and have never had such an impossible time getting the correct method called.
Thanks,
Adrian Perez
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Adrian Perez
2011-05-17 17:18:01 UTC
Permalink
Thank you for the snippets. I had poured over the unit tests and seen similar examples of how to do this already, but two commentless replies inspired me to trace through this in a debugger.

The issue ended up being that I was erroneously under the impression I was calling a static method, and was retrieving the method off of the 'type' object, rather than an instance of the type. The error you get back is the generic "no method matches given arguments", because my local 'desired_method' expected an initial 'self' argument, and so silently took 'arg_a' to be 'self'. This meant MethodBinder.Bind() only thought it had 1 input argument and could not match it to any of the overloads.

Cheers,

Adrian Perez


-----Original Message-----
From: BCline [mailto:bcline3078-***@public.gmane.org]
Sent: Tuesday, May 17, 2011 12:56 AM
Cc: Adrian Perez; pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: Re: [Python.NET] issue disambiguating overloaded method UPDATE


from System import String, Char, Int32
def TestCharArray():
from System import Array
charArrType = Array[Char]
##arrType = charArrType('hello')
##for char in arrType:
## print char,
## Also works on instances of the type! ##
strCharArr = String.__overloads__[charArrType]
s = strCharArr(list('hello'))
print s
TestCharArray()
Post by Barton
from System import Array
charArrType = Array[Char]
##arrType = charArrType('hello')
## print char,
## Also works on instances of the type! ##
strCharArr = s.__overloads__[charArrType]
s = strCharArr(list('hello'))
print s
Post by Adrian Perez
Hello everyone,
This is probably a total n00b question, but I've been using pythonnet
in our toolchain to communicate with a private c# assembly for months
now without ever running into a problem I couldn't eventually figure
out. This one has me totally stumped, and I'm hoping something
obvious will jump out at experienced eyes.
(I did a find/replace for secrecy, besides silly names these are the
raw results I get back)
A C# class exposes a method 'WriteByte' that has 5 overloads (note
accessor= MyCompany.SomeNamespace.SomeTypeArrayAccessor
accessor.WriteByte.__overloads__
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Byte[]) Boolean
WriteByte(MyCompany.SomeNamespace.SomeType, Byte[], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType,
System.Collections.Generic.IEnumerable`1[System.Byte], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Int32,
System.Collections.Generic.IEnumerable`1[System.Byte], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Int32, Byte[], Int32 ByRef)
desired_method=
accessor.WriteByte.__overloads__[MyCompany.SomeNamespace.SomeType,
System.Array[System.Byte]]
The problem may be right here - if I print out desired_method.__doc__
I get the same 5 methods listed above. Anyway, then I compute my
arguments, and can verify they have the types I expect (If it
matters, arg_b is created by a call to
arg_a= ...
arg_b= ...
type(arg_a)
<class 'MyCompany.SomeNamespace.SomeType'>
type(arg_b)
<class 'System.Byte[]'>
However, when I try to call the disambiguated method with the correct
result= desired_method(arg_a, arg_b)
File "<string>", line 1, in<fragment>
TypeError: No method matches given arguments
Does anyone see the obvious thing I'm doing wrong? Disambiguating
can be a pain but I've done it before for other methods and have
never had such an impossible time getting the correct method called.
Thanks,
Adrian Perez
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
BCline
2011-05-17 07:56:14 UTC
Permalink
from System import String, Char, Int32
def TestCharArray():
from System import Array
charArrType = Array[Char]
##arrType = charArrType('hello')
##for char in arrType:
## print char,
## Also works on instances of the type! ##
strCharArr = String.__overloads__[charArrType]
s = strCharArr(list('hello'))
print s
TestCharArray()
Post by Barton
from System import Array
charArrType = Array[Char]
##arrType = charArrType('hello')
## print char,
## Also works on instances of the type! ##
strCharArr = s.__overloads__[charArrType]
s = strCharArr(list('hello'))
print s
Post by Adrian Perez
Hello everyone,
This is probably a total n00b question, but I've been using pythonnet
in our toolchain to communicate with a private c# assembly for months
now without ever running into a problem I couldn't eventually figure
out. This one has me totally stumped, and I'm hoping something
obvious will jump out at experienced eyes.
(I did a find/replace for secrecy, besides silly names these are the
raw results I get back)
A C# class exposes a method 'WriteByte' that has 5 overloads (note
accessor= MyCompany.SomeNamespace.SomeTypeArrayAccessor
accessor.WriteByte.__overloads__
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Byte[])
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Byte[], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType,
System.Collections.Generic.IEnumerable`1[System.Byte], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Int32,
System.Collections.Generic.IEnumerable`1[System.Byte], Int32 ByRef)
Boolean WriteByte(MyCompany.SomeNamespace.SomeType, Int32, Byte[], Int32 ByRef)
desired_method=
accessor.WriteByte.__overloads__[MyCompany.SomeNamespace.SomeType,
System.Array[System.Byte]]
The problem may be right here - if I print out desired_method.__doc__
I get the same 5 methods listed above. Anyway, then I compute my
arguments, and can verify they have the types I expect (If it
matters, arg_b is created by a call to
arg_a= ...
arg_b= ...
type(arg_a)
<class 'MyCompany.SomeNamespace.SomeType'>
type(arg_b)
<class 'System.Byte[]'>
However, when I try to call the disambiguated method with the correct
result= desired_method(arg_a, arg_b)
File "<string>", line 1, in<fragment>
TypeError: No method matches given arguments
Does anyone see the obvious thing I'm doing wrong? Disambiguating
can be a pain but I've done it before for other methods and have
never had such an impossible time getting the correct method called.
Thanks,
Adrian Perez
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet

Loading...