Skip to content

Failure in function selection according to parameters #226

Closed

Description

@uenz

Hi,
until pythonnet 2.1.0 it was possible to call functions with the same name and different parameters. This fails with pythonnet 2.1.0
I have prepared minimal test functions like this, which return the input para string as string, int or float:
public String Function(String para, ref String myout)
public String Function(String para,ref int myout)
public String Function(String para,ref float myout)

and call them like this
from Test import TestClass
dummy=TestClass()

print dummy.Function('Echo',str())
print dummy.Function('42',int())
print dummy.Function('3.144',float())

With pythonnet==2.0.0 the result is as expected
(u'Echo', u'Echo')
(u'42', 42.0)
(u'3.144', 3.144)

pythonnet==2.1.0 returns a TypeError: No method matches given arguments

I have a sample dll and py as a zip, but unfortunately the upload fails.
(Unfortunately, we don’t support that file type. )

Activity

  1. den-run-ai commented on Jun 8, 2016

    @den-run-ai
    Contributor

    Method overloading was improved since pythonnet 2.0 - it could give you
    wrong overloaded method before!

    However ByRef is really complicated, since python does not support such a
    concept directly.

    In your case try this work-around by passing the actual CLR type:

    import System
    dummy.Function('Echo',System.String(""))

    Here is WIP patch that handles ByRef argument types. Just need to do more
    testing:

    #227

    On Wed, Jun 8, 2016 at 6:05 AM, uenz [email protected] wrote:

    Hi,
    until pythonnet 2.1.0 it was possible to call functions with the same name
    and different parameters. This fails with pythonnet 2.1.0
    I have prepared minimal test functions like this, which return the input
    para string as string, int or float:
    public String Function(String para, ref String myout)
    public String Function(String para,ref int myout)
    public String Function(String para,ref float myout)

    and call them like this
    from Test import TestClass
    dummy=TestClass()

    print dummy.Function('Echo',str())
    print dummy.Function('42',int())
    print dummy.Function('3.144',float())

    With pythonnet==2.0.0 the result is as expected
    (u'Echo', u'Echo')
    (u'42', 42.0)
    (u'3.144', 3.144)

    pythonnet==2.1.0 returns a TypeError: No method matches given arguments

    I have a sample dll and py as a zip, but unfortunately the upload fails.
    (Unfortunately, we don’t support that file type. )

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

  2. uenz commented on Jun 9, 2016

    @uenz
    Author

    Thanks for the response.
    The workaround with
    dummy.Function('Echo',System.String(""))
    unfortunately gives the same type error as mentioned.

  3. den-run-ai commented on Jun 9, 2016

    @den-run-ai
    Contributor

    Are you calling static or instance methods? If instance method, then did
    you initialize the object?

    Can you share your full example (both C# and python) in a gist on github?

    On Thursday, June 9, 2016, uenz [email protected] wrote:

    Thanks for the response.
    The workaround with
    dummy.Function('Echo',System.String(""))
    unfortunately gives the same type error as mentioned.

    —
    You are receiving this because you commented.
    Reply to this email directly, view it on GitHub
    #226 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe/AHgZ5SlMPJmoizoWJneWb_GhwlYcJJiCks5qJ6O6gaJpZM4Iw2BZ
    .

  4. den-run-ai commented on Jun 9, 2016

    @den-run-ai
    Contributor

    Anyway you can grab the branch from my pull request and build it yourself.

    On Thursday, June 9, 2016, Denis Akhiyarov [email protected]
    wrote:

    Are you calling static or instance methods? If instance method, then did
    you initialize the object?

    Can you share your full example (both C# and python) in a gist on github?

    On Thursday, June 9, 2016, uenz <[email protected]
    javascript:_e(%7B%7D,'cvml','[email protected]');> wrote:

    Thanks for the response.
    The workaround with
    dummy.Function('Echo',System.String(""))
    unfortunately gives the same type error as mentioned.

    —
    You are receiving this because you commented.
    Reply to this email directly, view it on GitHub
    #226 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe/AHgZ5SlMPJmoizoWJneWb_GhwlYcJJiCks5qJ6O6gaJpZM4Iw2BZ
    .

  5. uenz commented on Jun 10, 2016

    @uenz
    Author

    The code of the branch works well!

    A gist with the code is here:
    https://gist.github.com/uenz/b5eec565e4484595af98e0a620194229
    The DLL code is stripped down only to show the issue.
    Unfortunaltey i found no way to add also the compiled C# dll.

  6. den-run-ai commented on Sep 14, 2016

    @den-run-ai
    Contributor

    This issue requires implemented clr.Reference type properly in pythonnet. The issue is that during overload it is not possible to distinguish 2 overloads with the same signature except byref switched to byval. This is perfectly valid code in C#.

    Also related issues here:

    #228

    #236

  7. heri16 commented on May 6, 2017

    @heri16

    Is there a fix or workaround for this yet?

  8. den-run-ai commented on May 6, 2017

    @den-run-ai
    Contributor

    no fix yet, the workaround is using Reflection.

  9. filmor commented on Jun 14, 2022

    @filmor
    Member

    This should be fixed nowadays, if not, we should treat that as a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions