FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support to call C# named parameters from Python · Issue #849 · pythonnet/pythonnet · GitHub

Repository navigation

Support to call C# named parameters from Python #849

Closed

Description

Hi,
this is a change request:

Environment

  • Pythonnet version: 2.3.0.0
  • Python version: 3.6.5 32-bit
  • Operating System: Win 10

Details

In a python module, we want to call a C# Method, that has named optional parameters. But these are ignored.
Reason: The MethodBinder.Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, MethodInfo[] methodinfo) Method ignores the passed python keyword-arguments. But instead, it should assign them to the C# named parameters, if appropriate. Can you extend pythonnet to support named parameters?

snip

  • C#
public class LibWithDefault
{
    public static string FuncWithDefault(int x, object b = null)
    {
        return $"x: {x} b: {b} ";
    }
}
  • Python
import clr
clr.AddReference("CS_DefaultParam")
from CS_DefaultParam import LibWithDefault
res = LibWithDefault.FuncWithDefault(x=3, b=4)
print(res)

Activity

  1. changed the title [-]named parameters[/-] [+]C# named parameters support from python[/+] on Apr 16, 2019
  2. changed the title [-]C# named parameters support from python[/-] [+]support to call C# named parameters from python[/+] on Apr 16, 2019
  3. changed the title [-]support to call C# named parameters from python[/-] [+]Support to call C# named parameters from Python[/+] on Apr 23, 2019
  4. filmor commented on Apr 23, 2019

    Member

    Yes, this would be a fine addition and we're very open to PRs on this subject. Related, there is #80 that could be tackled at the same time.

  5. s4v4g3 commented on Sep 10, 2019

    Contributor

    PR submitted for this feature. By the way, it looks like #80 is already addressed since version 2.1. I added some tests to make sure named parameters & default parameters can work together OK.

  6. added a commit that references this issue on Sep 12, 2019
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


      Back | FazBrowse Home | New Git URL