Skip to content

py: Confusing error message when function passed a keyword arg that's not expected #2969

@dpgeorge

Description

@dpgeorge

Consider this code snippet:

def f(x):
    pass
f(y=1)

Errors reported are:

  • In CPython: TypeError: f() got an unexpected keyword argument 'y'
  • In uPy: TypeError: function does not take keyword arguments

I hit this when calling a user-defined function and was very confused because all user-defined functions accept keyword arguments (only built-in ones may not accept kw args). IMO the error message should at least be changed to be less confusing, but if we can spare bytes it should report which particular kw arg is causing the problem (and that's quite a simple change since at that point in the code it is known what the kw is that couldn't be found).

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