msg329781 - (view) |
Author: Emily Morehouse (emilyemorehouse) *  |
Date: 2018-11-13 00:52 |
This issue will serve to track development and PRs for the implementation of PEP 572: Assignment Expressions.
|
msg334325 - (view) |
Author: Emily Morehouse (emilyemorehouse) *  |
Date: 2019-01-24 23:50 |
New changeset 8f59ee01be3d83d5513a9a3f654a237d77d80d9a by Emily Morehouse in branch 'master':
bpo-35224: PEP 572 Implementation (#10497)
https://github.com/python/cpython/commit/8f59ee01be3d83d5513a9a3f654a237d77d80d9a
|
msg334328 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2019-01-25 00:01 |
This is huge!
I do recall there are some minor edge cases where the implementation currently doesn't match the PEP. Could you summarize those here, and add your recommendation (e.g. change the PEP, fix the code, wait and see) with motivation?
|
msg334330 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2019-01-25 00:29 |
The change broke most buildbots: congrats Emily, each core dev has to do their as part of their training ;-) Don't worry, it's fine.
I wrote PR #11670 which should fix test_tools.
|
msg334331 - (view) |
Author: Emily Morehouse (emilyemorehouse) *  |
Date: 2019-01-25 00:36 |
@vstinner Is there something I could/should have checked other than the CI displayed in GitHub before merging? Let me know if I can help.
Here's a brief summary of the differences between the PEP spec and implementation:
From the "Scope of the target" section of the PEP, there are two cases that should raise a TargetScopeError: when an assignment expression is used in a comprehension inside a class body or for special cases in comprehensions.
Invalid examples for the latter include:
[i := i+1 for i in range(5)]
[[(j := j) for i in range(5)] for j in range(5)]
[i := 0 for i, j in stuff]
[i+1 for i in i := stuff]
However, the following work in the implementation,though the PEP states they should be invalid:
>>> [i := i+1 for i in range(5)]
[1, 2, 3, 4, 5]
>>> i
5
>>> [i := 0 for i, j in [(1, 2)]]
[0]
The following does not work in the implementation (as desired), but does not throw a TargetScopeError as defined in the PEP:
>>> [i+1 for i in i := range(5)]
File "<stdin>", line 1
[i+1 for i in i := range(5)]
^
SyntaxError: invalid syntax
IMO, I was leaning towards advocating for changing the PEP to match the implementation. I think the error messages are clear and expected, and restricting what already works would require significant special cases. I'm open to discussion though.
There's also documentation that should certainly be added (and I believe a spot where assignment expressions are explicitly mentioned as not being included in the language, which is no longer the case)
|
msg334332 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2019-01-25 00:39 |
> @vstinner Is there something I could/should have checked other than the CI displayed in GitHub before merging? Let me know if I can help.
It wasn't your fault. Our pre-commit checks on pull requests is incomplete on purpose: it has to be fast. It's fine to break buildbots sometimes. It's a tradeoff.
If you want to help, please merge https://github.com/python/cpython/pull/11670 as soon as the CI test pass since I'm going to bed :-)
You are the victim of a very very specific annoying test, test_unparse with its annoying "randomly pick 10 files from the stdlib" feature...
|
msg334334 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2019-01-25 00:50 |
New changeset 1396d8fab4d0ae830d45f4937322bbb43ce0c30e by Victor Stinner in branch 'master':
bpo-35224: Add support for NamedExpr to unparse.py (GH-11670)
https://github.com/python/cpython/commit/1396d8fab4d0ae830d45f4937322bbb43ce0c30e
|
msg334341 - (view) |
Author: Karthikeyan Singaravelan (xtreak) *  |
Date: 2019-01-25 06:18 |
I don't know if this is the correct issue for questions/clarifications but 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.
|
msg334358 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2019-01-25 12:36 |
Note: I checked and 3.x buildbots are back to green (ignoring the ones which already failed previously). Good.
|
msg334839 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2019-02-04 20:08 |
FYI, we need a prominent Whatsnew entry for this.
|
msg334840 - (view) |
Author: Emily Morehouse (emilyemorehouse) *  |
Date: 2019-02-04 20:42 |
@rhettinger absolutely, I'm going to include that in my documentation PR which is currently in progress. :)
|
msg335437 - (view) |
Author: Miro Hrončok (hroncok) * |
Date: 2019-02-13 13:24 |
PEP 572 is nowhere to be found in https://docs.python.org/3.8/whatsnew/3.8.html
Should I open a separate issue for that?
|
msg335438 - (view) |
Author: Miro Hrončok (hroncok) * |
Date: 2019-02-13 13:32 |
(I've somehow missed the previous comments about the same, sorry about that.)
|
msg335452 - (view) |
Author: Emily Morehouse (emilyemorehouse) *  |
Date: 2019-02-13 15:29 |
I have a work-in-progress (WIP) documentation branch I've been working on that I'll push up this week to address the following:
- Add summary to What's New in Doc/whatsnew/3.8.rst
- Add to list of delimiters in Doc/reference/lexical_analysis.rst
- Add usage documentation in Doc/reference/expressions.rst
- Update FAQ in Doc/faq/design.rst (https://bugs.python.org/issue35666)
If anyone has another area they think the documentation should be updated, please let me know!
|
msg335458 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2019-02-13 15:48 |
> If anyone has another area they think the documentation should be updated, please let me know!
If we forget something, it's not an issue: it can be added later!
|
msg339098 - (view) |
Author: Vedran Čačić (veky) * |
Date: 2019-03-29 07:30 |
Now I had the opportunity to play with the walrus (as it is affectionately called in some parts of the community), I have to ask you for a reconsideration of one part of PEP 572.
Unparenthesized assignment expressions are prohibited at the top level of an expression statement. This rule is included to simplify the choice for the user between an assignment statement and an assignment expression -- there is no syntactic position where both are valid.
Correct, but the motivation rests on a wrong premise, that the effect is the same. In one very important case, it is not: in REPL (including things like Jupyter notebooks), the values of expressions are printed (if not None). I really hoped that the walrus would enable me to both assign and see the result at once. (Now it does, but I have to parenthesize, and that just looks ugly.)
More than half of the cells in my Jupyter notebooks are of the form
name = some.complicated.method(of={some: arguments})
name
another_name = another.method(name, [additional, arguments])
another_name
And while I understand why I had to write them like this before PEP 572, now I really think they would look much tidier as
name := some.complicated.method(of={some: arguments})
another_name := another.method(name, [additional, arguments])
Please reconsider.
|
msg339112 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2019-03-29 13:42 |
@veky -- please take this up on python-ideas.
|
msg339121 - (view) |
Author: Vedran Čačić (veky) * |
Date: 2019-03-29 15:19 |
Sorry, I don't have the energy for endless discussions without any result that almost always happen there. If you - of all people - don't see an obvious benefit of this (not even a feature - just a removal of a quite pointless limitation), then I'm probably wrong and there's no point in that.
|
msg339131 - (view) |
Author: Carol Willing (willingc) *  |
Date: 2019-03-29 18:40 |
@veky As a Jupyter notebook maintainer, I can see your point and I suspect some would like it. I'm not sure how big a benefit it would be for folks based on current notebook usage and practices. I just don't know. It's worth a discussion, but it should take place on python-ideas first to see how much traction your proposal would have.
Let's keep this issue focused on the implementation of 572 as accepted.
|
msg339159 - (view) |
Author: Steven D'Aprano (steven.daprano) *  |
Date: 2019-03-29 22:45 |
You are one person, who has used this feature for what, a month elapsed
time? 300 person-hours actual experience with it? Allowing top-level
unparenthisized walrus expressions will affect hundreds of thousands of
people, for collectively millions of hours over a decade or more of
elapsed time. What's the rush about lifting this restriction?
If the restriction turns out to be "pointless", then we can remove it
later, and no harm done. You say this is ugly in the notebooks:
(variable := expression)
but it is surely still an improvement over the status quo:
variable = expression; variable
But if we remove it now, and it turns out that it wasn't as pointless as
you thought, then we're stuck with a design mistake that will be very
hard to fix without breaking people's code.
I'm glad you've found an excellent use-case for unbracketed assignment
expressions, and I don't oppose your suggested change, I'm just
advocating caution.
Besides, Jypiter already allows interactive code that would be a syntax
error outside of their environment. They can probably relax that
restriction within Jypiter, while still leaving the language alone.
|
msg339160 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2019-03-29 23:04 |
The bug tracker is not the appropriate place to discuss a PEP. This issue is about the implementation of the PEP.
|
msg339172 - (view) |
Author: Vedran Čačić (veky) * |
Date: 2019-03-30 05:09 |
Carol, if you're willing to go into the lion's den that is Python-ideas with this, you have my eternal gratitude. :-)
Steven, sorry, there really is no rush. I really don't think I ever said there is. However, I think it would be much easier to change the behavior while the thing is in alpha. Isn't that the purpose of alpha?
(If I'm wrong here, please disregard. I would be fine to see this happening few years from now. I believe in "Python in the limit", not actual versions, but too many times I have been said "what you ask makes sense in the ideal world, but that ship has sailed long ago".)
Yes, of course (name := expression) is an improvement over what we have now, and I'm grateful for that. It's just that when I explain it to my students (" = is just assignment, := is for assignment and displaying"), I have no good reason to tell them why they must put the parentheses---except "Python is too worried you will make a mistake", and that just doesn't seem like something Python usually does. (That's something Java would do to people.:)
Yes, Jupyter sometimes does allow things that would otherwise be SyntaxErrors (though much less than they used to, since Python gave them a lot of headache by introducing decorators---if you remember that story;), and going to Jupyter was the next thing on my mind after I'm rejected here. I just thought it would be much easier to just allow this "at the source", so Jupyter people don't have to think "what if they finally allow toplevel walruses, but with different semantics (e.g., printing result even if it is None)?".
Carol and Victor, I'm sorry I have usurped a bugtracker issue for this discussion. First, I really thought this is about implementation of assignment expressions, and this is the best place to put it. Second, I didn't expect a discussion---I thought it would be either "that makes no sense, go away" or "yeah, good idea, we'll do it". For the next such issue (there will probably be one:), do you suggest that the more appropriate thing would be to open a new issue?
(Let me just reiterate that I'm not going to python-ideas. You probably can't understand how stressful that place is, but believe me, it is. I'm not the only one that thinks so. If that's the only sanctioned method to improve Python, even when it is about details, then I'll just withdraw from the game.)
|
msg340770 - (view) |
Author: Ned Batchelder (nedbat) *  |
Date: 2019-04-24 11:32 |
3.8.0a3 is out, and the What's New still doesn't mention this work yet.
|
msg340774 - (view) |
Author: Emily Morehouse (emilyemorehouse) *  |
Date: 2019-04-24 14:30 |
Ned is correct! I will be sprinting on docs for this at PyCon.
|
msg340776 - (view) |
Author: Ned Batchelder (nedbat) *  |
Date: 2019-04-24 14:50 |
Maybe we could update the What's New quickly now, and then get the longer more complex docs done later? People have been asking if this feature is in 3.8 because they don't see it mentioned.
|
msg340777 - (view) |
Author: Vedran Čačić (veky) * |
Date: 2019-04-24 15:01 |
... and probably also because they start Python, type
x := 2
and get SyntaxError (as explained above). ;-)
|
msg340792 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2019-04-24 16:57 |
I will add stub sections to the 3.8 whatsnew.
|
msg340794 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2019-04-24 17:15 |
> Maybe we could update the What's New quickly now, and then get the longer more complex docs done later? People have been asking if this feature is in 3.8 because they don't see it mentioned.
Here it is (PR 12941)
|
msg345782 - (view) |
Author: Jörn Heissler (joernheissler) * |
Date: 2019-06-16 21:42 |
Hello,
https://www.python.org/dev/peps/pep-0572/#change-to-evaluation-order mentions a change of evaluation order for dict comprehensions. It looks like this is not implemented yet (as of commit 66d47da8).
Will this be implemented in this issue, or should I create a new one?
Thanks
|
msg345791 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2019-06-16 23:26 |
Do you want to give it a try yourself?
On Sun, Jun 16, 2019 at 14:42 Jörn Heissler <report@bugs.python.org> wrote:
>
> Jörn Heissler <launchpad@joern.heissler.de> added the comment:
>
> Hello,
>
> https://www.python.org/dev/peps/pep-0572/#change-to-evaluation-order
> mentions a change of evaluation order for dict comprehensions. It looks
> like this is not implemented yet (as of commit 66d47da8).
>
> Will this be implemented in this issue, or should I create a new one?
>
> Thanks
>
> ----------
> nosy: +joernheissler
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue35224>
> _______________________________________
>
--
--Guido (mobile)
|
msg345798 - (view) |
Author: Jörn Heissler (joernheissler) * |
Date: 2019-06-17 03:43 |
I tried and it appears to work: https://github.com/python/cpython/pull/14139
As I'm not familiar with cpython code, chances are that I missed something important.
|
msg346282 - (view) |
Author: miss-islington (miss-islington) |
Date: 2019-06-22 14:40 |
New changeset c8a35417db8853a253517a3e5190e174075c6384 by Miss Islington (bot) (Jörn Heissler) in branch 'master':
bpo-35224: Reverse evaluation order of key: value in dict comprehensions (GH-14139)
https://github.com/python/cpython/commit/c8a35417db8853a253517a3e5190e174075c6384
|
msg346287 - (view) |
Author: Pablo Galindo Salgado (pablogsal) *  |
Date: 2019-06-22 18:08 |
All the stable 3.x Windows buildbots are failing since (https://github.com/python/cpython/pull/14139) was merged:
https://buildbot.python.org/all/#/builders/3/builds/3026
https://buildbot.python.org/all/#/builders/40/builds/2621
https://buildbot.python.org/all/#/builders/12/builds/2766
Extract from the logs:
2 tests failed:
test_asdl_parser test_clinic
======================================================================
ERROR: test_attributes (test.test_asdl_parser.TestAsdlParser)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\buildarea\3.x.bolen-windows10\build\lib\test\test_asdl_parser.py", line 64, in test_attributes
stmt = self.types['stmt']
KeyError: 'stmt'
======================================================================
ERROR: test_constructor_fields (test.test_asdl_parser.TestAsdlParser)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\buildarea\3.x.bolen-windows10\build\lib\test\test_asdl_parser.py", line 72, in test_constructor_fields
ehandler = self.types['excepthandler']
KeyError: 'excepthandler'
======================================================================
ERROR: test_definitions (test.test_asdl_parser.TestAsdlParser)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\buildarea\3.x.bolen-windows10\build\lib\test\test_asdl_parser.py", line 54, in test_definitions
self.assertIsInstance(self.types['withitem'], self.asdl.Product)
KeyError: 'withitem'
======================================================================
ERROR: test_product (test.test_asdl_parser.TestAsdlParser)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\buildarea\3.x.bolen-windows10\build\lib\test\test_asdl_parser.py", line 58, in test_product
alias = self.types['alias']
KeyError: 'alias'
======================================================================
ERROR: test_visitor (test.test_asdl_parser.TestAsdlParser)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\buildarea\3.x.bolen-windows10\build\lib\test\test_asdl_parser.py", line 119, in test_visitor
v.visit(self.types['mod'])
KeyError: 'mod'
======================================================================
FAIL: test_module (test.test_asdl_parser.TestAsdlParser)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\buildarea\3.x.bolen-windows10\build\lib\test\test_asdl_parser.py", line 45, in test_module
self.assertIn('stmt', self.types)
AssertionError: 'stmt' not found in {Sum([Construct....
----------------------------------------------------------------------
I cannot reproduce the error locally on my Windows 10 machine, but it fails consistently. I made a custom run in one of the buildbots and still fails:
https://buildbot.python.org/all/#/builders/3/builds/3027
|
msg346290 - (view) |
Author: Jörn Heissler (joernheissler) * |
Date: 2019-06-22 18:51 |
Pablo,
https://bugs.python.org/issue37359 was created yesterday, i.e. before the merge.
|
msg346291 - (view) |
Author: Jörn Heissler (joernheissler) * |
Date: 2019-06-22 18:55 |
Sorry,
I guess that's something completely different.
So maybe the issue is related to my pull request.
|
msg346292 - (view) |
Author: Jörn Heissler (joernheissler) * |
Date: 2019-06-22 19:24 |
My working theory:
The change modifies the MAP_ADD instruction and also what the instruction expects to find on the stack.
When *.pyc files are kept, the code generates the old stack layout (TOS=key, TOS1=value), but cpython will assume it's the other way round.
I.e. all *.pyc files created before the change won't work with later cpython versions, and vice versa.
I assume the build bots don't remove *.pyc files.
How large an issue is that?
|
msg346298 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2019-06-22 20:42 |
Ouch. That means we need to buy.p the puck format version number.
--
--Guido (mobile)
|
msg346303 - (view) |
Author: Pablo Galindo Salgado (pablogsal) *  |
Date: 2019-06-22 22:05 |
I have created PR14313 and triggered a custom build from that PR in the buildbots to confirm our hypothesis.
|
msg346304 - (view) |
Author: Pablo Galindo Salgado (pablogsal) *  |
Date: 2019-06-22 22:16 |
Although it can be related, note that the buildbots do indeed delete pyc files. Check for example https://buildbot.python.org/all/#/builders/40/builds/2621/steps/2/logs/stdio :
...
Deleting .pyc/.pyo files ...
Deleting test leftovers ...
Using "C:\buildbot.python.org\3.x.kloth-win64\build\PCbuild\\..\externals\pythonx86\tools\python.exe" (found in externals directory)
Fetching external libraries...
...
But I could be missing something. What I don't understand currently is why it fails only on the Windows buildbots.
|
msg346305 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2019-06-22 22:20 |
I don't know why the failure is Windows-only, but I suspect that some of
the cleanup doesn't work there...
This definitely needs a bump of the pyc format version number.
|
msg346306 - (view) |
Author: miss-islington (miss-islington) |
Date: 2019-06-22 22:34 |
New changeset 874ff65e0a70ff4fd1a67e85cd61d76adfcc219d by Miss Islington (bot) in branch '3.8':
bpo-35224: Reverse evaluation order of key: value in dict comprehensions (GH-14139)
https://github.com/python/cpython/commit/874ff65e0a70ff4fd1a67e85cd61d76adfcc219d
|
msg346307 - (view) |
Author: Pablo Galindo Salgado (pablogsal) *  |
Date: 2019-06-22 22:47 |
New changeset 663131a6e2c6c8b83e9f982d8c6ca38fc7c238b4 by Pablo Galindo in branch 'master':
bpo-35224: Bump the pyc magic number after the change in MAP_ADD (GH-14313)
https://github.com/python/cpython/commit/663131a6e2c6c8b83e9f982d8c6ca38fc7c238b4
|
msg346308 - (view) |
Author: miss-islington (miss-islington) |
Date: 2019-06-22 23:04 |
New changeset 5c8b4e2b5de647a67dd1b6414fa520d2b8e973aa by Miss Islington (bot) in branch '3.8':
bpo-35224: Bump the pyc magic number after the change in MAP_ADD (GH-14313)
https://github.com/python/cpython/commit/5c8b4e2b5de647a67dd1b6414fa520d2b8e973aa
|
msg346312 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2019-06-23 02:57 |
How are the buildbots doing now?
|
msg346319 - (view) |
Author: Pablo Galindo Salgado (pablogsal) *  |
Date: 2019-06-23 13:02 |
All buildbots for 3.8 and master are green again :)
|
msg346327 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2019-06-23 14:20 |
So issue29652 can be closed now? Was all concerns of previous discussions addressed?
I suggest to increment the magic number by 1, not by 10. The space of magic numbers is finite.
Add please a What's New entry for this change.
|
msg346329 - (view) |
Author: Pablo Galindo Salgado (pablogsal) *  |
Date: 2019-06-23 16:00 |
New changeset b3ca7972c8d8c6479b6542ce28e0f7a6ebd5b8fe by Pablo Galindo in branch 'master':
bpo-35224: Bump the pyc magic number by 1 instead of by 10 in last modification (GH-14320)
https://github.com/python/cpython/commit/b3ca7972c8d8c6479b6542ce28e0f7a6ebd5b8fe
|
msg346331 - (view) |
Author: miss-islington (miss-islington) |
Date: 2019-06-23 16:19 |
New changeset 175b2e974586152c1d4cdea589b971d7ecad4d30 by Miss Islington (bot) in branch '3.8':
bpo-35224: Bump the pyc magic number by 1 instead of by 10 in last modification (GH-14320)
https://github.com/python/cpython/commit/175b2e974586152c1d4cdea589b971d7ecad4d30
|
msg346472 - (view) |
Author: Pablo Galindo Salgado (pablogsal) *  |
Date: 2019-06-25 01:42 |
New changeset b51b7137faa22e12c570c70fe0462c662ccd935e by Pablo Galindo in branch 'master':
bpo-35224: Add What's new entry for evaluation order in dict comprehensions (GH-14319)
https://github.com/python/cpython/commit/b51b7137faa22e12c570c70fe0462c662ccd935e
|
msg346473 - (view) |
Author: miss-islington (miss-islington) |
Date: 2019-06-25 01:49 |
New changeset ced9e11931a7a1c5cf4eef08d0dd4a4886723b43 by Miss Islington (bot) in branch '3.8':
bpo-35224: Add What's new entry for evaluation order in dict comprehensions (GH-14319)
https://github.com/python/cpython/commit/ced9e11931a7a1c5cf4eef08d0dd4a4886723b43
|
msg347985 - (view) |
Author: Barry A. Warsaw (barry) *  |
Date: 2019-07-15 17:35 |
I might be missing it, but I think the Language Reference still doesn't document assignment expressions.
https://docs.python.org/3/reference/lexical_analysis.html#operators
There are likely other places in the LR that need to be filled out with PEP 572 documentation.
|
msg349011 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2019-08-05 00:13 |
Did the documentation PR get pushed/merged? Emily mentioned having one in progress above, but it doesn't appear in the linked PRs.
|
msg349013 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2019-08-05 00:16 |
https://bugs.python.org/issue37757 separates out the TargetScopeError handling for conflicts between assignment expressions and comprehension iteration variables.
|
msg349017 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2019-08-05 01:32 |
Also, a major procedural note: it is NOT OK to merge a PEP implementation that completely ignores parts of the PEP. The merged tests are actively forcing NON-compliance with the accepted PEP, since they're requiring implementations to accept code that the PEP explicitly states should be disallowed.
Those rules were added because the behaviour in CPython leaks CPython implementation details that we *don't want* to be part of the language specification.
|
msg349019 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2019-08-05 02:23 |
FWIW, I'm working on an improved whatsnew entry in https://github.com/python/cpython/pull/15127
|
msg349021 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2019-08-05 04:15 |
Thanks for catching that this was still incomplete.
> Also, a major procedural note: it is NOT OK to merge a PEP implementation that completely ignores parts of the PEP. The merged tests are actively forcing NON-compliance with the accepted PEP, since they're requiring implementations to accept code that the PEP explicitly states should be disallowed.
It was known the implementation was unfinished in this respect, but it was deemed better to merge what we had lest the work be lost in merge conflicts, and iterate in later betas. I've written some code that uses the walrus operator and have found it quite solid. The early existence of an implementation (albeit incomplete) has also helped get support for this in mypy (https://github.com/python/mypy/pull/6899).
I don't recall being aware that there were tests that specifically *checked* that the implementation was incomplete, and that's obviously wrong.
|
msg349024 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2019-08-05 04:32 |
#37757 now has an associated PR adding the missing TargetScopeError cases: https://github.com/python/cpython/pull/15131
There's one case where it goes beyond what the PEP specifies: because the outermost iterable expression gets evaluated in a different scope from the rest of the comprehension, it just flat out prohibits the use of assignment expressions in comprehension iterable expressions.
This was one of the cases where we explicitly didn't want the CPython implementation behaviour to leak into the language specification (as name binding in the outermost iterable expression would create an unrelated binding in the containing scope, while name binding in other iterable expressions would rebind any conflicting iteration variable in the comprehension), so the current PR takes the more conservative path, and defers allowing name binding in the iterable expressions until a specific use case for doing so is presented).
|
msg349025 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2019-08-05 04:36 |
Thanks Guido. The former test cases that the new PR removes are the following:
res = [i := i for i in range(5)]
res = [i := 0 for i, j in [(1, 2), (3, 4)]]
res = [(i := 0, j := 1) for i, j in [(1, 2), (3, 4)]]
res = [(i := i, j := j) for i, j in [(1, 2), (3, 4)]]
res = [(i := j, j := i) for i, j in [(1, 2), (3, 4)]]
These all raise TargetScopeError with the PR applied:
>>> res = [i := i for i in range(5)]
File "<stdin>", line 1
TargetScopeError: named expression cannot rebind comprehension iteration variable
>>> res = [i := 0 for i, j in [(1, 2), (3, 4)]]
File "<stdin>", line 1
TargetScopeError: named expression cannot rebind comprehension iteration variable
>>> res = [(i := 0, j := 1) for i, j in [(1, 2), (3, 4)]]
File "<stdin>", line 1
TargetScopeError: named expression cannot rebind comprehension iteration variable
>>> res = [(i := i, j := j) for i, j in [(1, 2), (3, 4)]]
File "<stdin>", line 1
TargetScopeError: named expression cannot rebind comprehension iteration variable
>>> res = [(i := j, j := i) for i, j in [(1, 2), (3, 4)]]
File "<stdin>", line 1
TargetScopeError: named expression cannot rebind comprehension iteration variable
|
msg349026 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2019-08-05 04:49 |
Can you suggest a PEP update too, for the case that goes beyond the PEP?
And please provide examples (not everybody knows immediately what
"outermost iterable expression" refers to. :-)
|
msg349034 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2019-08-05 07:37 |
Proposed PEP update is here: https://github.com/python/peps/pull/1140
The update also aims to clarify *why* we're doing the extra work in CPython's compiler to make these cases fail (i.e. we don't want to implicitly impose the current CPython runtime behaviour on other implementations)
|
msg351906 - (view) |
Author: miss-islington (miss-islington) |
Date: 2019-09-11 14:37 |
New changeset 6357c95716d89ac1f80587fbc4133df8d2e8396c by Miss Islington (bot) (Emily Morehouse) in branch 'master':
bpo-35224: Additional documentation for Assignment Expressions (GH-15935)
https://github.com/python/cpython/commit/6357c95716d89ac1f80587fbc4133df8d2e8396c
|
msg351929 - (view) |
Author: Stéphane Wirtel (matrixise) *  |
Date: 2019-09-11 15:12 |
New changeset be2aa58fdc29cf13aabff6d6712e7853e94e88f8 by Stéphane Wirtel (Miss Islington (bot)) in branch '3.8':
bpo-35224: Additional documentation for Assignment Expressions (GH-15935) (GH-15967)
https://github.com/python/cpython/commit/be2aa58fdc29cf13aabff6d6712e7853e94e88f8
|
msg351933 - (view) |
Author: Emily Morehouse (emilyemorehouse) *  |
Date: 2019-09-11 15:16 |
All areas that were identified for additional work have been addressed.
If there is anything else that needs to be improved or updated, please create a new issue.
Thanks!
|
msg351940 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2019-09-11 15:29 |
Congrats! Let's party.
|
|
Date |
User |
Action |
Args |
2022-04-11 14:59:08 | admin | set | github: 79405 |
2019-09-11 15:29:33 | gvanrossum | set | messages:
+ msg351940 |
2019-09-11 15:16:49 | emilyemorehouse | set | status: open -> closed messages:
+ msg351933
keywords:
patch, patch resolution: fixed stage: patch review -> resolved |
2019-09-11 15:12:13 | matrixise | set | nosy:
+ matrixise messages:
+ msg351929
|
2019-09-11 14:37:23 | miss-islington | set | pull_requests:
+ pull_request15600 |
2019-09-11 14:37:15 | miss-islington | set | messages:
+ msg351906 |
2019-09-11 13:02:01 | emilyemorehouse | set | pull_requests:
+ pull_request15572 |
2019-08-05 07:37:17 | ncoghlan | set | keywords:
patch, patch
messages:
+ msg349034 |
2019-08-05 04:49:30 | gvanrossum | set | messages:
+ msg349026 |
2019-08-05 04:36:52 | ncoghlan | set | keywords:
patch, patch
messages:
+ msg349025 |
2019-08-05 04:32:26 | ncoghlan | set | keywords:
patch, patch
messages:
+ msg349024 |
2019-08-05 04:15:06 | gvanrossum | set | keywords:
patch, patch
messages:
+ msg349021 |
2019-08-05 02:23:32 | rhettinger | set | keywords:
patch, patch
messages:
+ msg349019 |
2019-08-05 01:32:23 | ncoghlan | set | keywords:
patch, patch
messages:
+ msg349017 |
2019-08-05 00:16:11 | ncoghlan | set | keywords:
patch, patch
messages:
+ msg349013 |
2019-08-05 00:13:10 | ncoghlan | set | keywords:
patch, patch nosy:
+ ncoghlan messages:
+ msg349011
|
2019-07-15 17:35:38 | barry | set | keywords:
patch, patch nosy:
+ barry messages:
+ msg347985
|
2019-06-25 01:49:11 | miss-islington | set | messages:
+ msg346473 |
2019-06-25 01:42:12 | miss-islington | set | pull_requests:
+ pull_request14178 |
2019-06-25 01:42:03 | pablogsal | set | messages:
+ msg346472 |
2019-06-23 16:19:31 | miss-islington | set | messages:
+ msg346331 |
2019-06-23 16:01:07 | miss-islington | set | pull_requests:
+ pull_request14145 |
2019-06-23 16:00:11 | pablogsal | set | messages:
+ msg346329 |
2019-06-23 15:12:30 | pablogsal | set | pull_requests:
+ pull_request14144 |
2019-06-23 15:09:04 | pablogsal | set | pull_requests:
+ pull_request14143 |
2019-06-23 14:20:14 | serhiy.storchaka | set | keywords:
patch, patch nosy:
+ serhiy.storchaka messages:
+ msg346327
|
2019-06-23 13:02:47 | pablogsal | set | keywords:
patch, patch
messages:
+ msg346319 |
2019-06-23 02:57:11 | gvanrossum | set | keywords:
patch, patch
messages:
+ msg346312 |
2019-06-22 23:04:47 | miss-islington | set | messages:
+ msg346308 |
2019-06-22 22:47:43 | miss-islington | set | pull_requests:
+ pull_request14138 |
2019-06-22 22:47:38 | pablogsal | set | messages:
+ msg346307 |
2019-06-22 22:34:14 | miss-islington | set | messages:
+ msg346306 |
2019-06-22 22:20:53 | gvanrossum | set | messages:
+ msg346305 |
2019-06-22 22:16:20 | miss-islington | set | pull_requests:
+ pull_request14137 |
2019-06-22 22:16:00 | pablogsal | set | keywords:
patch, patch
messages:
+ msg346304 |
2019-06-22 22:05:05 | pablogsal | set | keywords:
patch, patch
messages:
+ msg346303 |
2019-06-22 22:03:50 | pablogsal | set | pull_requests:
+ pull_request14136 |
2019-06-22 20:42:24 | gvanrossum | set | messages:
+ msg346298 |
2019-06-22 19:24:39 | joernheissler | set | messages:
+ msg346292 |
2019-06-22 18:55:08 | joernheissler | set | messages:
+ msg346291 |
2019-06-22 18:51:54 | joernheissler | set | messages:
+ msg346290 |
2019-06-22 18:08:45 | pablogsal | set | keywords:
patch, patch nosy:
+ pablogsal messages:
+ msg346287
|
2019-06-22 14:40:58 | miss-islington | set | nosy:
+ miss-islington messages:
+ msg346282
|
2019-06-17 03:43:49 | joernheissler | set | messages:
+ msg345798 |
2019-06-17 03:39:07 | joernheissler | set | pull_requests:
+ pull_request13980 |
2019-06-16 23:26:20 | gvanrossum | set | messages:
+ msg345791 |
2019-06-16 21:42:05 | joernheissler | set | nosy:
+ joernheissler messages:
+ msg345782
|
2019-05-07 16:13:07 | Rosuav | set | pull_requests:
+ pull_request13077 |
2019-04-24 17:15:06 | gvanrossum | set | keywords:
patch, patch
messages:
+ msg340794 |
2019-04-24 17:13:50 | gvanrossum | set | pull_requests:
+ pull_request12865 |
2019-04-24 16:57:07 | gvanrossum | set | keywords:
patch, patch
messages:
+ msg340792 |
2019-04-24 15:01:14 | veky | set | messages:
+ msg340777 |
2019-04-24 14:50:35 | nedbat | set | keywords:
patch, patch
messages:
+ msg340776 |
2019-04-24 14:30:25 | emilyemorehouse | set | keywords:
patch, patch
messages:
+ msg340774 |
2019-04-24 11:32:57 | nedbat | set | keywords:
patch, patch nosy:
+ nedbat messages:
+ msg340770
|
2019-03-30 05:09:47 | veky | set | messages:
+ msg339172 |
2019-03-29 23:36:08 | vstinner | set | keywords:
patch, patch nosy:
- vstinner
|
2019-03-29 23:04:30 | vstinner | set | keywords:
patch, patch
messages:
+ msg339160 |
2019-03-29 22:45:15 | steven.daprano | set | messages:
+ msg339159 |
2019-03-29 18:40:49 | willingc | set | keywords:
patch, patch nosy:
+ willingc messages:
+ msg339131
|
2019-03-29 17:18:14 | hroncok | set | nosy:
- hroncok
|
2019-03-29 15:19:00 | veky | set | messages:
+ msg339121 |
2019-03-29 13:42:54 | gvanrossum | set | keywords:
patch, patch
messages:
+ msg339112 |
2019-03-29 07:30:09 | veky | set | nosy:
+ veky messages:
+ msg339098
|
2019-02-20 02:13:24 | koobs | set | keywords:
patch, patch nosy:
+ koobs
|
2019-02-13 15:48:34 | vstinner | set | keywords:
patch, patch
messages:
+ msg335458 |
2019-02-13 15:29:17 | emilyemorehouse | set | keywords:
patch, patch
messages:
+ msg335452 |
2019-02-13 13:32:41 | hroncok | set | messages:
+ msg335438 |
2019-02-13 13:24:31 | hroncok | set | nosy:
+ hroncok messages:
+ msg335437
|
2019-02-04 20:42:34 | emilyemorehouse | set | keywords:
patch, patch
messages:
+ msg334840 |
2019-02-04 20:08:01 | rhettinger | set | keywords:
patch, patch nosy:
+ rhettinger messages:
+ msg334839
|
2019-01-25 12:36:00 | vstinner | set | keywords:
patch, patch
messages:
+ msg334358 |
2019-01-25 06:18:34 | xtreak | set | keywords:
patch, patch
messages:
+ msg334341 |
2019-01-25 00:50:09 | vstinner | set | messages:
+ msg334334 |
2019-01-25 00:39:46 | vstinner | set | keywords:
patch, patch
messages:
+ msg334332 |
2019-01-25 00:36:34 | emilyemorehouse | set | keywords:
patch, patch
messages:
+ msg334331 |
2019-01-25 00:29:27 | vstinner | set | keywords:
patch, patch nosy:
+ vstinner messages:
+ msg334330
|
2019-01-25 00:27:54 | vstinner | set | pull_requests:
+ pull_request11483 |
2019-01-25 00:27:47 | vstinner | set | pull_requests:
+ pull_request11482 |
2019-01-25 00:27:38 | vstinner | set | pull_requests:
+ pull_request11481 |
2019-01-25 00:01:04 | gvanrossum | set | keywords:
patch, patch
messages:
+ msg334328 |
2019-01-24 23:50:00 | emilyemorehouse | set | messages:
+ msg334325 |
2019-01-05 16:29:59 | serhiy.storchaka | link | issue35666 dependencies |
2018-11-13 10:15:10 | steven.daprano | set | keywords:
patch, patch nosy:
+ steven.daprano
|
2018-11-13 05:43:59 | xtreak | set | keywords:
patch, patch nosy:
+ xtreak
|
2018-11-13 01:32:02 | eric.smith | set | keywords:
patch, patch nosy:
+ eric.smith
|
2018-11-13 01:08:12 | emilyemorehouse | set | keywords:
+ patch stage: patch review pull_requests:
+ pull_request9759 |
2018-11-13 01:08:10 | emilyemorehouse | set | keywords:
+ patch stage: (no value) pull_requests:
+ pull_request9758 |
2018-11-13 00:52:17 | emilyemorehouse | create | |