On 8/18/2016 12:50 PM, Steve Dower wrote:
> I'm generally inclined to agree, especially as someone who is very
> likely to be implementing syntax highlighting and completion support
> within f-literals.

I consider these separate issues. IDLE currently provides filename completion support within strings while still highlighting the string one color. Even if it were enhanced to do name completion within an f-string, I am not sure I would want to put a mixture of colors within the string rather than leave if all one color.

> I stepped out of the original discussion near the start as it looked
> like we were going to end up with interleaved strings and normal
> expressions, but if that's not the case then it is going to make it
> very difficult to provide a nice coding experience for them.

This is the crux of this thread. Is an f-string a single string that contains magically handled code, or interleaved strings using { and } as closing and opening quotes (which is backwards from their normal function of being opener and closer) and expressions? The latter view makes the grammar context sensitive, I believe, as } could only open a string if there is a previous f-tagged string an indefinite number of alternations back.

It is not uncommon to write strings that consist completely of code.
  "for i in iterable: a.append(f(i))"
to be written out or eval()ed or exec()ed.
Does your environment have a mode to provide syntax highlighting and completion support for such things?

What I think would be more useful would be the ability to syntax check such code strings while editing. A python-coded editor could just pass the extracted string to compile().

I don't think f'{x.partition('-')[0]}' is any less readable as a result
of the reused quotes,

I find it hard to not read f'{x.partition(' + ')[0]}' as string concatenation.

and it will certainly be easier for highlighters
to handle (assuming they're doing anything more complicated than simply
displaying the entire expression in a different colour).

Without the escapes, existing f-unaware highlighters like IDLE's will be broken in that they will highlight the single f-string as two strings with differently highlighted content in the middle. For f'{x.partition('if')[0]}', the 'if' is and will be erroneously highlighted as a keyword. I consider this breakage unacceptible.

--
Terry Jan Reedy

_______________________________________________
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