[IronPython] Method overload

J. Merrill jvm_cop at spamcop.net
Tue Jan 10 18:07:05 CET 2006


Clearly, having IP make the right which-overload decision a very high percentage of the time is desirable, but it's not a "portability of my Python code" issue if I need to do something special to invoke the desired overload.  But it is _critical_ that we be able to determine, in IP alone (without VS debugger), which overload was actually selected.

One solution would be to provide a way to iterate (in Python) through the (presumed by me to exist, without looking at the code) internal structure that describes the cached mapping of whatever-is-that-is-stored to .Net MethodInfo objects.

Providing access to that structure as a Python dictionary (perhaps __overloads__ within Python function/method objects?) could permit user code to add and/or change entries and thus control things when that is needed.  It would also let us write tests that exercise the IP code that makes the decisions and be certain that the results are as desired -- without having to write .Net methods that have particular parameter patterns and that somehow inform us about what the choice was.

[Thinking out loud] Hmm, a Python program that took a .Net assembly/class spec, reflected through its callable methods, and produced a c# source file that defined IPOverloadTest_classname_methodname methods with the same signatures as all the methods with multiple overloads, where the implementation somehow records that it's been called, would not be that hard to write.  So perhaps the "so we can write tests of the overload resolution mechanism" use for what I described above would not be necessary.  (Has anyone there written this?  Should one of us?)

Good luck trying to figure out the best way to do this!!

At 02:18 PM 1/9/2006, Martin Maly wrote

>There is a syntax for selecting the overload. However, I didn t mention it because we want to achieve state where the automatic binding we have satisfies most uses. More importantly, the selection mechanism may change in the near future.
>
> 
>
>Having said that, yes, it is possible to select the very overload by using the square bracket syntax. However, this may change during our beta cycles so try to not depend on it too much.
>
> 
>
>Martin
>
> 
>
>>>> from System import Console
>
>>>> Console.Write(3)
>
>3>>> Console.Write[str](3)
>
>Traceback (most recent call last):
>
>  File , line 0, in input##2
>
>TypeError: bad args to this method <method# Write on System.Console>
>
>>>> 
>
> 
>
>----------
>From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of J. Merrill
>Sent: Monday, January 09, 2006 9:32 AM
>To: Discussion of IronPython
>Subject: Re: [IronPython] Method overload
>
> 
>
>Isn't there a syntax (using []) by which you can tell IP explicitly which one it should use?  I was expecting you to say what you did, but to add info about that as well.
>
>At 12:48 AM 1/8/2006, Martin Maly wrote
>
>Yes, it will work on .NET. IronPython will try to find the best fit among the overloads based on types of arguments that you pass to the method call. There may be cases when IronPython may not choose the right method & and we want to hear about those cases so we can fix them.
>
>Martin
>
>----------
>From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Fabio
>Sent: Saturday, January 07, 2006 4:42 PM
>To: IronPython
>Subject: [IronPython] Method overload
>
>I'm studing IronPython and I liked very much!
>But I have one question.
>
>In .Net Framework, several classes has method overload. In my study, Python does not support method overload, and when we define  methods with the same name, they are redefined then only the last is used.
>
>How IronPython handle this? By example, the method "System.Console.Write()" has 18 overloads! This will work in .Net?
>
>Regards
>Fabio


J. Merrill / Analytical Software Corp 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060110/4b640320/attachment.html>


More information about the Ironpython-users mailing list