On Thu, 2020-04-16 at 21:21 -0700, Andrew Barnert via Python-ideas wrote: > On Apr 16, 2020, at 20:48, [email protected] wrote: > > In Javascript ES6 they don't have sets built like python so `{}` > > always refers to objects being constructed. It does indeed support > > implicit key: value pairs, so in ES6 `{ a: a, b: x, c: c }` is > > equivalent to `{ a, b: x, c }`. This is okay for Javascript users > > because they would not thought it as sets and the only obvious > > assumption to make is that parameters are being implicitly assigned > > to members. This is not the case in Python so I would refrain from > > changing dictionary literals syntax. > > Obviously the exact same syntax as ES6 doesn’t work in Python, > because it would be not just confusing but ineradicably ambiguous > with sets. > > But I don’t see why that rules out the “bare colon” form that I and > someone else apparently both proposed in separate sub threads of this > thread: > > { :a, "b": x, :c } > > as shorthand for: > > { "a": a, "b": x, "c": c } >
It likely does not matter, but one argument in favor of only applying
such syntax to function calls is that in function calls there is no
ambiguity that "a" is a string:
dict(a=a)
cannot possibly be thought to mean:
{a: a}
instead of:
{"a": a}
That may be a pretty moot point, but if you have a dictionary that does
not use strings as keys things might just a tiny bit strange?
- Sebastian
> There’s no problem for the parser. Make a trivial change to the
> grammar to add a `":" identifier` alternative to dict display items,
> and nothing becomes ambiguous.
>
> And I don’t think it would be confusing to a human reader. It can’t
> possibly be a set, because colons are what make a dict display not a
> set display, and there are colons.
>
> And I think extending dict display syntax is more powerful and less
> disruptive than extending call syntax. It means you can refactor the
> {…} in a **{…} if the call gets too unwieldy; it means calls and
> other places with ** unpacking remain consistent; etc.
>
>
> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/IEPZ7WBQC6FOG3IYHGQV4IJEZUBJHSUO/
> Code of Conduct: http://python.org/psf/codeofconduct/
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/4MVSQDJBZDRLZLPIFOFQ5OUH4ZSM4GNH/ Code of Conduct: http://python.org/psf/codeofconduct/
