We are discussing a proposal to extend Python's syntax to allow
    d[1, 2, a=3, b=4]

We are also discussing the associated semantics. At present
    d[1, 2]
    d[(1, 2)]
are semantically equivalent.

There is a proposal, that
    d[1, 2, a=3, b=4]
    d[(1, 2), a=3, b=4]
be semantically equivalent.

I find this troubling, for example because
   fn(1, 2, a=3, b=4)
   fn((1, 2), a=3, b=4)
are semantically different.

Here's another example. If we are allowed to write
    d[*argv, a=3, b=4]
then the proposal makes this equivalent to
   d[argv, a=3, b=4]
when type(argv) is tuple.

Consider now
    >>> def fn(*argv): print(argv)
    >>> argv = 'key'
    >>> fn(*argv)
    ('k', 'e', 'y')

I think it would be a trap for the unwary, that the equivalence of
   d[argv, a=3, b=4]
   d[*argv, a=3, b=4]
depends on the type of argv.

The root of the proposal that
    d[1, 2, a=3, b=4]
    d[(1, 2), a=3, b=4]
be semantically equivalent is this: At present
    d[1, 2]
    d[(1, 2)]
are semantically equivalent.

Why not instead , as part of the proposed semantics, make
    d[1, 2]
    d[(1, 2)]
semantically different, but only for those classes that ask for it. (This
would automatically preserve backwards compatibility.)

I believe this is possible and straightforward in the future, and also in
the present via the 'o' and K mechanism. I'm happy to implement this in
kwkeys, when I have time.

An aside: I also strongly believe that writing and studying examples that
use the new syntax, via the 'o' and K mechanism, is essential to making
good choices regarding the semantics, the writing and approval of the PEP,
and the success of the extension to Python (should the PEP be accepted).

I hope this helps us come to a shared understanding.
-- 
Jonathan
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/L3TSE4FZ2L7ETEW2JUD3W24LTFOJMEHF/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to