Skip to content

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

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'

Activity

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