[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Thanks a lot Guido and Emily for guidance on this issue. Happy to see this for 
alpha release :)

--

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Emily Morehouse


Change by Emily Morehouse :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Emily Morehouse


Emily Morehouse  added the comment:


New changeset ac19081c26eaa7de3e6aabeb789ddc2e7cdd5b24 by Emily Morehouse in 
branch 'master':
bpo-35877: Add test for while loop named expression without parentheses 
(GH-11726)
https://github.com/python/cpython/commit/ac19081c26eaa7de3e6aabeb789ddc2e7cdd5b24


--

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Emily Morehouse


Emily Morehouse  added the comment:

Thanks, Karthikeyan! I added an additional test to make sure this gets 
coverage. I'll close out this issue once tests pass and I can merge that.

--

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Emily Morehouse


Change by Emily Morehouse :


--
pull_requests: +11608, 11609, 11610

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Emily Morehouse


Change by Emily Morehouse :


--
pull_requests: +11608

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Emily Morehouse


Change by Emily Morehouse :


--
pull_requests: +11608, 11609

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Emily Morehouse


Emily Morehouse  added the comment:


New changeset d4fceaafb8e3f8700d9ec6ab37a51e903392f74f by Emily Morehouse 
(Xtreak) in branch 'master':
bpo-35877: Make parenthesis optional for named expression in while statement 
(GH-11724)
https://github.com/python/cpython/commit/d4fceaafb8e3f8700d9ec6ab37a51e903392f74f


--

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
keywords: +patch, patch, patch
pull_requests: +11603, 11604, 11605
stage: needs patch -> patch review

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
keywords: +patch, patch
pull_requests: +11603, 11604
stage: needs patch -> patch review

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
keywords: +patch
pull_requests: +11603
stage: needs patch -> patch review

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

> Thanks, Karthikeyan! Can you submit that as a PR?

Sure, I will submit the patch with tests for the same.

Thanks

--

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Guido van Rossum


Guido van Rossum  added the comment:

Thanks, Karthikeyan! Can you submit that as a PR?

--

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Karthikeyan Singaravelan

Karthikeyan Singaravelan  added the comment:

> Emily, I think this would be as simple as making a tiny change to 
> Grammar/Grammar and running make regen-grammar. Can you take care of that?

Thanks, can confirm that this fixes the issue. I changed test to namedexpr_test 
for while statement in grammar and ran `make regen-grammar` and `make`. The 
reported program runs fine and Lib/test/test_named_expressions.py also passes.

➜  cpython git:(master) ✗ cat /tmp/foo.py
import re

with open("/tmp/foo.py") as f:
while line := f.readline():
if match := re.search(r"foo", line):
print(match.string.strip("\n"))
➜  cpython git:(master) ✗ ./python.exe /tmp/foo.py
with open("/tmp/foo.py") as f:
if match := re.search(r"foo", line):


Patch : 

➜  cpython git:(master) ✗ git diff | cat
diff --git a/Grammar/Grammar b/Grammar/Grammar
index e65a688e4c..a425978059 100644
--- a/Grammar/Grammar
+++ b/Grammar/Grammar
@@ -72,7 +72,7 @@ assert_stmt: 'assert' test [',' test]
 compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | 
funcdef | classdef | decorated | async_stmt
 async_stmt: 'async' (funcdef | with_stmt | for_stmt)
 if_stmt: 'if' namedexpr_test ':' suite ('elif' namedexpr_test ':' suite)* 
['else' ':' suite]
-while_stmt: 'while' test ':' suite ['else' ':' suite]
+while_stmt: 'while' namedexpr_test ':' suite ['else' ':' suite]
 for_stmt: 'for' exprlist 'in' testlist ':' [TYPE_COMMENT] suite ['else' ':' 
suite]
 try_stmt: ('try' ':' suite
((except_clause ':' suite)+
diff --git a/Python/graminit.c b/Python/graminit.c
index 6e0f19891b..5cdde2789c 100644
--- a/Python/graminit.c
+++ b/Python/graminit.c
@@ -971,7 +971,7 @@ static arc arcs_42_0[1] = {
 {103, 1},
 };
 static arc arcs_42_1[1] = {
-{26, 2},
+{99, 2},
 };
 static arc arcs_42_2[1] = {
 {27, 3},

--

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Guido van Rossum


Guido van Rossum  added the comment:

Emily, I think this would be as simple as making a tiny change to 
Grammar/Grammar and running make regen-grammar. Can you take care of that?

--
assignee:  -> emilyemorehouse
stage:  -> needs patch

___
Python tracker 

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



[issue35877] parenthesis is mandatory for named expressions in while statement

2019-02-01 Thread Karthikeyan Singaravelan

New submission from Karthikeyan Singaravelan :

I thought to open a separate report itself in order to keep the original issue 
not cluttered with questions since it could be used for other docs. Sorry for 
my report there. Original report as per msg334341 .

It seems parens are mandatory while using named expressions in while statement 
which makes some of the examples invalid like 
https://www.python.org/dev/peps/pep-0572/#sysconfig-py . From my limited 
knowledge while statement Grammar was not modified at 
https://github.com/python/cpython/pull/10497/files#diff-cb0b9d6312c0d67f6d4aa1966766ceddR73
 and no tests for while statement which made me assume it's intentional. I 
haven't followed the full discussion about PEP 572 so feel free to correct me 
if it's a conscious decision and in that case the PEP 572 can be updated.

# python info

➜  cpython git:(master) ./python.exe
Python 3.8.0a0 (heads/bpo35113-dirty:49329a217e, Jan 25 2019, 09:57:53)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

# Example as in PEP 572 to create a simple file that reads itself and prints 
lines that matches "foo"

➜  cpython git:(master) cat /tmp/foo.py
import re

with open("/tmp/foo.py") as f:
while line := f.readline():
if match := re.search(r"foo", line):
print(match.string.strip("\n"))
➜  cpython git:(master) ./python.exe /tmp/foo.py
  File "/tmp/foo.py", line 4
while line := f.readline():
   ^
SyntaxError: invalid syntax

# Wrapping named expression with parens for while makes this valid

➜  cpython git:(master) cat /tmp/foo.py
import re

with open("/tmp/foo.py") as f:
while (line := f.readline()):
if match := re.search(r"foo", line):
print(match.string.strip("\n"))
➜  cpython git:(master) ./python.exe /tmp/foo.py
with open("/tmp/foo.py") as f:
if match := re.search(r"foo", line):


As a user I think parens shouldn't be mandatory in while statement since if 
statement works fine. Parens can cause while statement to be superfluous in 
some cases and an extra case to remember while teaching.

--
components: Interpreter Core
messages: 334665
nosy: emilyemorehouse, gvanrossum, xtreak
priority: normal
severity: normal
status: open
title: parenthesis is mandatory for named expressions in while statement
type: behavior
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