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

PythonNET unknown kwargs being discarded · Issue #2360 · pythonnet/pythonnet · GitHub

Repository navigation

PythonNET unknown kwargs being discarded  #2360

Open

Description

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

Activity

  1. balogun14 commented on Oct 7, 2024

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

  2. filmor commented on Oct 7, 2024

    Member
  3. lostmsu commented on Oct 7, 2024

    Member

    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.

  4. filmor commented on Oct 7, 2024

    Member

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

  5. lostmsu commented on Oct 18, 2024

    Member

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

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

    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