[issue36798] := breaks f-strings

2019-05-05 Thread Eric V. Smith


Eric V. Smith  added the comment:

The fact that adding := support could break existing working code does give me 
pause to make any change here, and does suggest that a deprecation period would 
be needed in order to modify the f-string expression scanning behavior.

One concern I have is that if something akin to PEP 536 is used to implement 
f-strings, then it would require some work (but not be impossible) to avoid 
allowing :=.

In 3.8, := is prohibited in "expression as a statement" mode, but that's not 
the mode that f-strings expressions operate in: they're just normal 
expressions, and I would normally just expect := to work. But the backward 
compatibility break here is the reason to possibly disallow supporting :=, not 
that := should just never work in f-strings without parens.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-05 Thread Larry Hastings


Larry Hastings  added the comment:

I'm not sure why Guido's preferences would be relevant.  f-strings support 
expressions, := is a valid expression, f-strings therefore must support it. 
 f-strings expressions are not top-level statements and therefore will not 
require parentheses around :=.

There appears to be some confusion around f-strings' use of : to delimit a 
"format specification".  Supporting := won't break format specifications, 
although it will require some intelligence--if you see a :, you must examine 
the next character to know whether it's := or a format specification.  It is 
not a breaking change.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-05 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Note that Guido prefers to use parentheses around the assignment operator even 
if the grammar does nor require this. He used this style in What's New.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-05 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

There was a note on PEP 572 
(https://www.python.org/dev/peps/pep-0572/#exceptional-cases) to prohibit as a 
top level expression and a discussion on the issue also didn't agree with it 
https://bugs.python.org/issue35224#msg339098 . It might cause confusion to 
users due to this difference inside and outside of f-strings.

--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-05 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Allowing it at the top level is a breaking change. It should not be done 
without deprecation. And I think that it is better to use parenthesis around 
the assignment operator (or better do not use it in f-strings at all) that 
deprecate the "=" alignment.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-05 Thread Eric V. Smith


Eric V. Smith  added the comment:

Correct about the parens. I'm just going to fix it a the top level, without 
parens. There's no reason it shouldn't work, the fact that it doesn't work now 
is just an accident of implementation.

I'll fix it by adding a special test, the same way that != has a special test.

For those who say it shouldn't be allowed at the top level anyway, but should 
be allowed in parens: if we decide that (which I disagree with), then it should 
not be disallowed because of an accidental interaction with format specs. It 
should be explicitly checked for and disallowed. Again, I am not planning on 
making that change. I'm just going to allow it.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-05 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

You can use it in parenthesis:

>>> f'{(x:=10)}'
'10'

It should be explicitly documented, that what looks like the assignment 
operator is not always the assignment operator in f-strings.

>>> x = 10
>>> f'{x:=10}'
'10'

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-05 Thread Eric V. Smith


Eric V. Smith  added the comment:

f-strings are not going to take a position on what a "good" expression is, and 
what is and isn't allowed. If it's a Python expression that could possibly be 
parsed in the f-string context, f-strings will allow it. This is clearly a bug 
in 3.8. I'll have a PR today or during the sprints.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-05 Thread SilentGhost


SilentGhost  added the comment:

> The point is that := is valid expression syntax in Python 3.8, but you can't 
> use it in an f-string.

Good? Allowing walrus operator in the f-strings will just lead to the debugging 
hell.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-05 Thread Larry Hastings


Larry Hastings  added the comment:

The point is that := is valid expression syntax in Python 3.8, but you can't 
use it in an f-string.  The fact that the error is the same in 3.6 and 3.7 is 
irrelevant because := was not valid syntax in those versions.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-05 Thread SilentGhost


SilentGhost  added the comment:

This doesn't seem at all related to walrus operator, I can reproduce this error 
on 3.6.7 and 3.7.3, given that format call returns exactly the same error, it 
seems like '=' is simply not a valid alignment for strings.

I'm not saying that walrus operator did not introduce any errors, but those 
could be perhaps best tested using the following code:

f'{x:=^10}'

--
nosy: +SilentGhost

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-04 Thread Barry A. Warsaw


Change by Barry A. Warsaw :


--
nosy: +barry

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-04 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +emilyemorehouse

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36798] := breaks f-strings

2019-05-04 Thread Eric V. Smith


New submission from Eric V. Smith :

The walrus operator breaks f-strings, because the f-string scanner sees the 
colon as the end of the expression.

>>> x = '10'
>>> f'{x:=10}'
Traceback (most recent call last):
  File "", line 1, in 
ValueError: '=' alignment not allowed in string format specifier

This becomes: format(x, '=10'), which is an error if x is a string.

--
assignee: eric.smith
components: Interpreter Core
messages: 341413
nosy: eric.smith, larry, lukasz.langa
priority: release blocker
severity: normal
status: open
title: := breaks f-strings
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com