[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread Steven D'Aprano
On Tue, Jun 30, 2020 at 10:25:45PM +1000, Chris Angelico wrote: > Be careful of semantics here. I'm not sure which languages do what, > but I just checked Perl, and "\x{1234}" is equivalent to Python's > "\u1234", not to "\x12\x34". This proposal is for the latter, which > could be sneakily confus

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread Steven D'Aprano
On Tue, Jun 30, 2020 at 09:04:15PM +0300, Mikhail V wrote: > > Counter-proposal: hex escapes allow optional curly brackets, similar to > > unicode name escapes. You could even allow spaces within the braces, for > > grouping: > > > > # Proposed enhancement: > > "\x{2b}2c" # '+2c' > >

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread Mikhail V
On Tue, Jun 30, 2020 at 5:05 AM Steven D'Aprano wrote: > For single-character escape codes, I see no benefit at all to this, only > disadvantages. However I do see a tiny potential benefit to hex escapes, > for the rare occassions that they are immediately followed by something > that looks like

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread MRAB
On 2020-06-30 17:20, Chris Angelico wrote: On Wed, Jul 1, 2020 at 1:57 AM MRAB wrote: On 2020-06-30 13:25, Chris Angelico wrote: > On Tue, Jun 30, 2020 at 2:28 PM MRAB wrote: >> >> On 2020-06-30 02:14, Steven D'Aprano wrote: >> [snip] >> > Counter-proposal: hex escapes allow optional curly br

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread Chris Angelico
On Wed, Jul 1, 2020 at 1:57 AM MRAB wrote: > > On 2020-06-30 13:25, Chris Angelico wrote: > > On Tue, Jun 30, 2020 at 2:28 PM MRAB wrote: > >> > >> On 2020-06-30 02:14, Steven D'Aprano wrote: > >> [snip] > >> > Counter-proposal: hex escapes allow optional curly brackets, similar to > >> > unicode

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread MRAB
On 2020-06-30 13:25, Chris Angelico wrote: On Tue, Jun 30, 2020 at 2:28 PM MRAB wrote: On 2020-06-30 02:14, Steven D'Aprano wrote: [snip] > Counter-proposal: hex escapes allow optional curly brackets, similar to > unicode name escapes. You could even allow spaces within the braces, for > group

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread Chris Angelico
On Tue, Jun 30, 2020 at 2:28 PM MRAB wrote: > > On 2020-06-30 02:14, Steven D'Aprano wrote: > [snip] > > Counter-proposal: hex escapes allow optional curly brackets, similar to > > unicode name escapes. You could even allow spaces within the braces, for > > grouping: > > > > # Existing: > >

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-30 Thread Guido van Rossum
On Mon, Jun 29, 2020 at 21:30 MRAB wrote: > On 2020-06-30 02:14, Steven D'Aprano wrote: > [snip] > > Counter-proposal: hex escapes allow optional curly brackets, similar to > > unicode name escapes. You could even allow spaces within the braces, for > > grouping: > > > > # Existing: > >

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-29 Thread Rob Cliffe via Python-ideas
On 29/06/2020 15:29, Mikhail V wrote: Proposal: Allow standard python escapes inside curly braces in f-strings. Main point is to make clear visual distinction between text and escaped chars: # current syntax: print ("\nnewline") print ("\x0aa") # new syntax: print (f"{\

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-29 Thread MRAB
On 2020-06-30 02:14, Steven D'Aprano wrote: [snip] Counter-proposal: hex escapes allow optional curly brackets, similar to unicode name escapes. You could even allow spaces within the braces, for grouping: # Existing: "\N{HYPHEN-MINUS}" # '-' "\x2b" # '+' # Proposed enhanc

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-29 Thread Steven D'Aprano
On Mon, Jun 29, 2020 at 05:29:31PM +0300, Mikhail V wrote: > Proposal: > > Allow standard python escapes inside curly braces in f-strings. > Main point is to make clear visual distinction between text and > escaped chars: There is already a clear visual distinction between text and escaped chars

[Python-ideas] Re: Escapes inside curly braces in f-strings

2020-06-29 Thread Eric V. Smith
The reason backslashes don't currently work is because of how they'd interact with string parsing. I don't think this will change until we move f-string parsing into the grammar itself, instead of happening as a post-processing step in ast.c. See bpo-33754 for one example of this. There have be