PythonNET unknown kwargs being discarded

Hi,

When accessing a .NET function using PythonNET bindings I noticed that if a kwarg is incorrect or doesn’t exist it is discarded by the PythonNET parser. For example

If I have a .NET function like this:

Public Function SomeFunction(name as String, age as String) as String
    Return $"{name} - {age}"
End Function

And I call it in PythonNET like this:


if __name__ == "__main__":
    name = "John"
    age = "3"
    SomeFunction(name, age=age, fake_arg="something")

The fake arg is discarded and no error or exception is thrown. The python compiles as if the additional kwarg is not there. In this situation normal python would be throwing a TypeError.

This is an issue for us when we have multiple kwargs in our methods/functions that a user can easily misspell and result in unexpected behaviour.

Hi Hamish,

Could you please upload a sample project you’re using to call such a .NET function from Python code?

Most likely, we will need to forward it to Python.NET team to investigate.

Kind regards,
Dmitry

Hi Hamish,

We reproduced this issue at our end; it does look like Python.NET engine does not validate arguments of this kind. We will try to get their comments on this issue.

Kind regards,
Dmitry

1 Like

Hi Dmitry,

Was there any update on this?

Hi Hamish,

No, not really. I’ve posted an issue a while ago here:
PythonNET unknown kwargs being discarded · Issue #2360 · pythonnet/pythonnet · GitHub, however, they haven’t even acknowledged it.

Kind regards,
Dmitry

No worries, thanks Dmitry!

Hi Hamish,

It looks like there’s some activity related to this issue. However, it’s hard to tell if it’s going to be resolved any time soon:

Kind regards,
Dmitry