GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||
GeezerVison is showing github.com — gh-87447: Fix walrus comprehension rebind checking by sobolevn · Pull Request #100581 · python/cpython Conversation
|
|
Sorry, I did not click on the second reviewer the first time! :( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I'm not very familiar with symtable, but left one comment.
I think it might also need a little more consensus that this is something that should be fixed; I tried to restart discussion in #87447 (comment)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| long target_in_scope = _PyST_GetSymbol(ste, target_name); | ||
| if (target_in_scope & DEF_COMP_ITER) { | ||
| if ((target_in_scope & DEF_COMP_ITER) && | ||
| (target_in_scope & (DEF_LOCAL | DEF_GLOBAL))) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hmm, should this also check DEF_NONLOCAL?
Actually, looking closer, I think DEF_GLOBAL might be impossible, because we already check for it when setting DEF_COMP_ITER. Or at least, tests pass without checking DEF_GLOBAL here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks! With the fix, the code seems reasonable to me, but I'm not comfortable enough with this module for that to mean much.
I think this merits a What's New entry, along the lines of https://docs.python.org/3/whatsnew/3.11.html#other-language-changes
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| exec(f"lambda: {code}", {}) # Function scope | ||
|
|
||
| def test_named_expression_valid_rebinding_list_comprehension_iteration_variable(self): | ||
| cases = [ |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment at the start of the test explaining that we are cheching that anything that is not directly a comprehension iteration variable (a or b) can be assigned to?
Also, we probably should ensure ALL comprehensions are covered by the test (add another for loop that changes the brackets).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done! Except for dict comprehensions. Looks like they are not tested in test_named_expressions at all. I've opened a new task for it here: #100746
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work @sobolevn!
Let's leave some time for @emilyemorehouse in case she wants to take a look and we can land it then. If this is not landed in a week or so, please ping me and I will land it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Pablo Galindo Salgado <[email protected]>
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…e-87447.7-aekA.rst
Co-authored-by: Shantanu <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The implementation of this looks great, thanks @sobolevn!
I went back and forth a bit on whether the underlying issue should be fixed in this way and ultimately agree – the current behavior is certainly confusing and while I'm not highly motivated by the use cases, it makes sense given that we allow the use of local variables in assignment expressions in other scenarios. I'm also in favor of leaving this as a change for 3.12 and not backporting.
Thanks, all!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.