[Python-ideas] kwargs for return
Steven D'Aprano
steve at pearwood.info
Sat Jan 26 08:51:06 EST 2019
On Sat, Jan 26, 2019 at 02:04:12PM +0100, Thomas Güttler Lists wrote:
> Example:
>
> status = backend.transmit_data()
>
> But later you want to add something to the API.
[...]
> How could kwargs for return look like?
return {'status': True, 'messages': []}
Or perhaps better:
return ResultObject(status=True, messages=[])
I don't see anything here that can't be done by returning a dict, a
namedtuple (possibly with optional fields), or some other object with
named fields. They can be optional, they can have defaults, and you can
extend the object by adding new fields without breaking backwards
compatibility.
--
Steve
More information about the Python-ideas
mailing list