ariovistus / pyd

Interoperability between Python and D
MIT License
157 stars 32 forks source link

Support of named arguments? #135

Closed andre2007 closed 3 years ago

andre2007 commented 4 years ago

Is there any support of named arguments in pyd? I have following python call, I would like to translate to D

boto3.client('sqs', region_name='eu-central-1')

(In this specific case, region_name is also the second positional argument of the method, but what would I do, if it would be the 12th positional argument?)

andre2007 commented 4 years ago

For the method sqs.get_queue_url (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs.html#SQS.Client.get_queue_url) only key arguments are allowed as it is defined as get_queue_url(**kwargs)

Running ./pydsample pyd.exception.PythonException@/home/user/.dub/packages/pyd-0.13.1/pyd/infrastructure/pyd/pydobject.d(544): TypeError: get_queue_url() only accepts keyword arguments.

ariovistus commented 4 years ago

looks like the PydObject has a unpack_call(PydObject args, PydObject kwargs) method

andre2007 commented 4 years ago

@ariovistus do you know by chance how I can create a kwargs PydObject? Can I create it based on a tuple (https://dlang.org/phobos/std_typecons.html#.Tuple)?

ariovistus commented 4 years ago

unpack_call is going to correspond to a python call like

method(*args, **kwargs)

so kwargs needs to be a python dict. something like

PydObject kwargs = py(["region_name":"eu-central-1"]);
andre2007 commented 3 years ago

Thanks.