[Python-ideas] kwargs for return

Wes Turner wes.turner at gmail.com
Sat Jan 26 11:59:36 EST 2019

On Saturday, January 26, 2019, Steven D'Aprano <steve at pearwood.info> wrote:
> Perhaps you should start by telling us *precisely* what the problem is
> that your subclass will solve. Because I don't know what your idea of
> dict unpacking is, and how it compares or differs from previous times it
> has been proposed.

Dataclasses initialization may be most useful currently implemented
syntactic sugar for a dict return value contract that specifies a variable
name (and datatype)?

Is there a better way to specify a return object interface with type
annotations that throws exceptions at runtime that dataclasses?

> Are there any other languages which support dict unpacking? How does it
> work there?

This about object destructuring in JS is worth a read:


Here are two simple cases:

var o = {p: 42, q: true};
var {p: foo, q: bar} = o;

console.log(foo); // 42
console.log(bar); // true

Does it throw an exception when a value is undefined?
You can specify defaults:

var {a: aa = 10, b: bb = 5} = {a: 3};

console.log(aa); // 3
console.log(bb); // 5

> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190126/7aefc4d8/attachment.html>

More information about the Python-ideas mailing list