Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PythonNET unknown kwargs being discarded #2360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dmitry-medvedev opened this issue Apr 19, 2024 · 5 comments · May be fixed by #2590
Open

PythonNET unknown kwargs being discarded #2360

dmitry-medvedev opened this issue Apr 19, 2024 · 5 comments · May be fixed by #2590
Labels

Comments

@dmitry-medvedev
Copy link

dmitry-medvedev commented Apr 19, 2024

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

@filmor filmor added the bug label Aug 22, 2024
@balogun14
Copy link

@filmor @dmitry-medvedev @lstratman @henon @slide i will like to work on this issue

@filmor
Copy link
Member

filmor commented Oct 7, 2024

@balogun14 Great. The function that is probably buggy is https://github.com/pythonnet/pythonnet/blob/master/src/runtime/MethodBinder.cs#L372.

@lostmsu
Copy link
Member

lostmsu commented Oct 7, 2024

I am nearly sure this will have to stay this way until the next major version, because fixing it may break code that relied on discarding of unused kwargs (which is the default behavior of Python in case kwargs argument is present).

There's also a descent chance that there are certain scenarios where strict behavior like requested would make implementation hard or even impossible, but I can't remember anything on the spot.

@filmor
Copy link
Member

filmor commented Oct 7, 2024

Let's just see what comes out of it. We can always introduce flags that could be set at init/load-time.

@lostmsu
Copy link
Member

lostmsu commented Oct 18, 2024

@filmor would you really double our testing matrix for this?

@generalloki generalloki linked a pull request May 6, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants