Skip to content

Disambiguating an overloaded method with multiple parameters #1099

@integerfn

Description

@integerfn

Environment

  • Pythonnet version: 2.3.0 and 2.4.0
  • Python version: 3.6.5
  • Operating System: W10

Details

The C# side

    public enum MyEnum: byte
    {
        Success= (byte)'S',
        Error = (byte)'E'
    }

    public class MyClass
    {
        public Dictionary<Enum, BlockingCollection<ISomeInterface>> MyDictionary { get; }

        public MyClass()
        {
            MyDictionary = new Dictionary<Enum, BlockingCollection<ISomeInterface>>(); 
        }
    }

On the python side, I began with this code

    from System.Collections.Concurrent import BlockingCollection
    from MyModule import MyClass, ISomeInterface, MyEnum

    obj = MyClass()
    collection = BlockingCollection[ISomeInterface]()
    obj.MyDictionary.Add(MyEnum.Success, collection)

This fails with TypeError: No method matches given arguments for Add. I've tried what seemed to solve it for #935 but get the same results

    from System.Collections.Concurrent import BlockingCollection
    from System import Enum
    from MyModule import MyClass, ISomeInterface, MyEnum

    obj = MyClass()
    collection = BlockingCollection[ISomeInterface]()
    obj.MyDictionary.Add[Enum, BlockingCollection[ISomeInterface]](MyEnum.Success, collection)

This fails with TypeError: No match found for given type params

  • The output of print(obj.MyDictionary.Add.__overloads__) is
    Void Add(System.Enum, System.Collections.Concurrent.BlockingCollection`1[MyModule.ISomeInterface])

UPDATE

Running this code alone actually works, add shows as a bound method in the debugger:

add = obj.MyDictionary.Add.Overloads[Enum, BlockingCollection[ISomeInterface]]

However, attempting to call the function always fails. I've attempted passing System.byte and 0, instead of the enum, but none of them work.

add(MyEnum.Success, collection)
obj.MyDictionary.Add[Enum, BlockingCollection[ISomeInterface]](MyEnum.Success, collection)
obj.MyDictionary.Add.Overloads[Enum, BlockingCollection[ISomeInterface]](MyEnum.Success, collection)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions