Your library seems difficult to extract values from nested dictionary, and
when the key is not an identifier it's also embarrassed.

For sure we can have a library using graphql syntax to extract data from
the dict of any schema,  but that's not my point.

I'm focused on the consistency of the language itself.

    {key: value_pattern, **_} = {key: value, **_}

The reason why it's important is that, when destructing/constructing for
built-in data structures are not supported completely,
people might ask why "[a, *b] = c" is ok but "{"a": a, **b} = c" not.
If only multiple assignment is supported, why "(a, (b, c)) = d" could be
ok? It's exactly destructing!
And then if people think destructing of data structures is ok, they might
be curious about what's the boundary of this feature.
If you just tell them, "oh, it's just special, it just works for iterables,
even you can partially destruct the dict in argument passing, you cannot
use it in a simple statement!"


    >> def f(a, b, **c):
              print (a, b, c)
     >> f(a=1,  **{'b': 2})
     1 2 {}

     >> {'a': a, 'b': b, **c} = {'a': 1, **{'b': 2}}
     SyntaxError: can't assign to literal

Above example could be confusing in some degree, I think. If we don't have
so many convenient helpers for function call,
in terms of consistency, it might be even better...


2018-04-10 9:23 GMT+08:00 Joao S. O. Bueno <jsbu...@python.org.br>:

> On 9 April 2018 at 22:10, Brett Cannon <br...@python.org> wrote:
> >
> >
> > On Mon, 9 Apr 2018 at 05:18 Joao S. O. Bueno <jsbu...@python.org.br>
> wrote:
> >>
>
> >> we could even call this approach a name such as "function call".
> >
> >
> > The harsh sarcasm is not really called for.
>
> Indeed - on rereading, I have to agree on that.
>
> I do apologize for the sarcasm. - really, I not only stand corrected:
> I recognize i was incorrect to start with.
>
> But my argument that this feature is needless language bloat stands.
>
> On the othe hand, as for getting variable names out of _shallow_  mappings,
> I've built that feature in a package I authored, using a context manager
> to abuse the import mechanism -
>
> In [96]: from extradict import MapGetter
>
> In [97]: data = {"A": None, "B": 10}
>
> In [98]: with MapGetter(data):
>    ...:     from data import A, B
>    ...:
>
> In [99]: A, B
> Out[99]: (None, 10)
>
>
> That is on Pypi and can be used by anyone right now.
>
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to