<div dir="auto">I was going to write exactly they're same idea Steven did. <div dir="auto"><br></div><div dir="auto">Right now you can simply design APIs to return dictionaries or, maybe better, namedtuples. Namedtuples are really nice since you can define new attributes when you upgrade an API without breaking any old coffee that used the prior attributes... Of course, you can only add more, not remove old ones, to assure compatibility. Unlike dictionaries, namedtuples cannot contain arbitrary "keywords" at runtime, which is either good or bad depending on your purposes.</div><div dir="auto"><br></div><div dir="auto">Recently, dataclasses are also an option. They are cool, but I haven't yet had a reason to use them. They feel heavier than namedtuples though (as a programming construct, not talking about memory usage or speed or whatever).</div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Jan 26, 2019, 8:52 AM Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sat, Jan 26, 2019 at 02:04:12PM +0100, Thomas Güttler Lists wrote:<br>
<br>
> Example:<br>
><br>
>     status = backend.transmit_data()<br>
> <br>
> But later you want to add something to the API.<br>
[...]<br>
> How could kwargs for return look like?<br>
<br>
return {'status': True, 'messages': []}<br>
<br>
Or perhaps better:<br>
<br>
return ResultObject(status=True, messages=[])<br>
<br>
<br>
I don't see anything here that can't be done by returning a dict, a <br>
namedtuple (possibly with optional fields), or some other object with <br>
named fields. They can be optional, they can have defaults, and you can <br>
extend the object by adding new fields without breaking backwards <br>
compatibility.<br>
<br>
<br>
<br>
<br>
-- <br>
Steve<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank" rel="noreferrer">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div>