Skip to content

Incorrect function resolution when calling overloads from python with keyword args #1097

@jmlidbetter

Description

@jmlidbetter

Environment

  • Pythonnet version: 2.4.0
  • Python version: 3.6.5
  • Operating System: Centos

Details

  • Describe what you were trying to get done.

    When calling .NET functions with overloads from python with keyword args, the MethodBinder.Bind method will return the first method it finds which might not be the actual method the user is trying to call. Take the following simple C# code:

public static string OptionalArgumentsMethod(int arg1, int arg2)
{ 
    return $"{arg1}{arg2}XX";
}

public static string OptionalArgumentsMethod(int arg1, int arg2, int arg3 = 3)
{
    return $"{arg1}{arg2}{arg3}X";
}

public static string OptionalArgumentsMethod(int arg1, int arg2, int arg3 = 4, int arg4 = 5)
{
    return $"{arg1}{arg2}{arg3}{arg4}";
}

Calling, for example, OptionalArgumentsMethod(1, 2, arg3=5) we expect to get back 125X but instead we see:

>>> OptionalArgumentsMethod(1, 2)
'12XX'
>>> OptionalArgumentsMethod(1, 2, 3)
'123X'
>>> OptionalArgumentsMethod(1, 2, arg3=5)
'12XX'
>>> OptionalArgumentsMethod(1, 2, 3, 5)
'1235'
>>> OptionalArgumentsMethod(1, 2, 3, arg4=5)
'123X'
>>> OptionalArgumentsMethod(1, 2, arg4=0)
'12XX'

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy