Skip to content

Weird (mis)behaviour when passing kwarg along with *args #11439

@mirko

Description

@mirko

When using the following library[1] I experienced a weird error:

Frozen module / copied into some importable path makes no difference.
I'm having the following interaction with the repl:

>>> from mp_modbus_master import modbus_rtu_master
>>> modbus_rtu_master()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/TMP/mp_modbus_master.py", line 513, in __init__
TypeError: unexpected keyword argument 'rtu'
>>>

Looking at the code, though, (https://github.com/eydam-prototyping/mp_modbus/blob/master/mp_modbus_master.py#L513) there's no kwarg rtu.
The only occurrence of the string "rtu" is the default value to the kwarg ms_type in that line.
That this string "rtu" is indeed the one seen as kwarg by mpy is confirmed by changing it to "XXX" - whereas mpy then complains about TypeError: unexpected keyword argument 'XXX'

Minimal test case showing this behaviour (thanks to @jimmo):

def a(x="y"):
    print(x)

def b(*args):
    a(x="z", *args)

b()

resulting in

Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "<stdin>", line 5, in b
TypeError: unexpected keyword argument 'z'

[1]https://github.com/eydam-prototyping/mp_modbus

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpy-coreRelates to py/ directory in source

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy