Skip to content

PythonNET unknown kwargs being discarded  #2360

@dmitry-medvedev

Description

@dmitry-medvedev

Environment

  • Pythonnet version: 3.0.3
  • Python version: 3.11
  • Operating System: Windows 10
  • .NET Runtime: .NET 8.0

Details

When accessing a .NET function using PythonNET, if a kwarg is incorrect or doesn’t exist, it is discarded by the PythonNET execution engine

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. Python compiles as if the additional kwarg were not there. In this situation, normal Python would be throwing a TypeError.

This is an issue with a multiple kwargs in the methods/functions is that a user can easily misspell and result in unexpected behavior.

PythonDemo.zip

Metadata

Metadata

Assignees

No one assigned

    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