I would not be a fan of this approach (even though I agree it's technically
feasible). The problem is that if a user simply forgets the colon at the
end of a line (surely a common mistake), the modified parser would produce
a much more confusing error on a subsequent line.

With the PEG parser we could support this:

with (
    open("file1") as f1,
    open("file2") as f2,
):
    <code>

But there would still be an ambiguity if it were to see

with (
    lock1.acquire(),
    lock2.acquire(),
):
    <code>

Is that a simple tuple or a pair of context managers that are not assigned
to local variables? I guess we can make it the latter since a tuple
currently fails at runtime, but the ice is definitely thin here.


On Thu, Nov 14, 2019 at 10:14 AM Andrew Barnert via Python-ideas <
python-ideas@python.org> wrote:

> On Nov 14, 2019, at 09:53, Andrew Barnert via Python-ideas <
> python-ideas@python.org> wrote:
> >
> > Yeah, it seems like this should be doable in basically the same way
> bracketed multiline expressions are. I’m not sure how much of a change that
> would require. But it seems like it’s worth fiddling with the CPython
> parser to see if it can actually be done, rather than guessing.
>
> Actually; as an intermediate proof of concept without getting into hacking
> the parser, you could hack the pure-Python version of the tokenizer in the
> tokenize module. IIRC, it has code in a couple places that decides whether
> to yield a NEWLINE (logical end of line) or an NL (physical end of line
> that’s just whitespace rather than logical end of line), and whether to
> check indent level and yield INDENT/DEDENT tokens, based on keeping track
> of the open bracket count and a backslash flag and probably something else
> for triple-quoted strings. You’d probably just need to add another flag for
> the head line of a compound statement to those two places, and the code to
> set and clear that flag in a couple other places, and that’s it.
>
> And then you can run it on a whole mess of code and verify that it’s only
> different in the cases where you want it to be different (what used to be
> an ERRORTOKEN or NEWLINE is now an NL because we’re in the middle of a with
> compound statement header).
>
> _______________________________________________
> 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/ZXT5VX2GLHYICHXPIG5GUNQD6D6FE33K/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
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/256JPRMZXCUS2TFPN2CS5D6KK3PQ4L64/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to