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-74929: Implement PEP 667 by gaogaotiantian · Pull Request #115153 · python/cpython Conversation
|
|
Thanks for doing this! I was hoping this would get done for 3.13 but hadn't found time to do it yet.
EDIT: on second thought, I realized the problem is likely that |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes, that's why the test fails. The test is |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I cleaned up the code a bit to address the review and added the GC part in. This is still in draft state, which only aims to demostrate the possibility of PEP 667. There's plenty of work to be done before this can be merged in. The current goal is to make it enough for the PSF to decide whether to accept PEP 667. Let me know if there's still missing pieces (like do we want to actually remove all the FAST/LOCAL conversion calls to prove the point). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Removing the fast locals <--> slow locals conversion is key to fixing #74929. I think that is worth doing before submitting PEP 667 to the SC. @gaogaotiantian since you are doing most of the work on this, would you like to be added as co-author of PEP 667? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sure, I'm happy to be listed as the co-author. I'll work on the fast vs local thing and check if #74929 is fixed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
FWIW the discussion has been started at https://discuss.python.org/t/pep-667-consistent-views-of-namespaces/46631. We now need at least the following updates to the PEP:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I've already added myself to the list of authors with Mark's guidance. Let me know if you want me to make the PR to update the PEP. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Go right ahead. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@markshannon okay I made all fast/local related functions no-op. It did not break anything new and #74929 (comment) is not an issue anymore. The original test case in #74929 has been accidentally fixed in 3.11, is there any repro case that I can test against? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Is there a reason you're leaving the failing tests as failing? I think it is easier for reviewers to evaluate the compatibility impact on tests by seeing the required changes to tests in the PR, rather than by having to go look at the CI test results. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The current implementation is just a prototype and far from being done. I can make some modifications to the test so they can pass with the change if that's preferred. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
We have two more months until feature freeze. If we want to land this on 3.13, we probably should push it forward soon. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
How is the Discourse discussion on this topic going? Is it substantial enough to send the PEP to the SC? Do we need to make any PEP updates first? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I made a PR to the PEP and it's approved but not merged (I think Mark has to review and approve it?), if you meant the link changes mentioned before. I'm not sure if the discussion thread attracts enough attention. What point should we get for the Disclosure discussion? |
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.
|
We need to decide which mapping methods we want Dunder methods
I think we need to support all the above, except pickling, and that Normal methods
Methods that remove items are tricky as we cannot properly delete fast locals; we just set them to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
We don't need to implement them all before submitting the PEP though, just decide on which methods to support. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Should we follow some standard for the methods we should implement? The original PEP mentioned that we should do a For the remove related methods - should the debugger be able to decref the local variable? Just like |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Okay I resolved most of the comments, and I believe there's one thing left here - comprehensions. I'm just going to jump to my proposal and see if that makes sense. If not, we can discuss it more. import sys def f(): x = 1 [print(sys._getframe().f_locals) for a in [0]] print([sys._getframe().f_locals for a in [0]][0]) print(sys._getframe().f_locals) f() will print Notice all the values above are proxies. import sys class C: x = 1 [print(sys._getframe().f_locals) for a in [0]] print([sys._getframe().f_locals for a in [0]][0]) print(sys._getframe().f_locals) will print (ignore An alternative would be: The latter seems more consistent with the function level result, and it makes Maybe we could stick to a simple rule here - However, this will break the backwards compatibility for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think that proposal looks reasonable. I think your first proposal for the class behavior is better. Comprehensions in class scope cannot see class-level variables (as if the comprehension were still a function, since functions defined in a class scope can't see variables in the enclosing class scope either), so those class variables should not show up when |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
But we will probably treat module-level the same as class-level. Do you think it's reasonable to have a module-level comprehension to return a proxy without the global variables? edit: I guess that makes sense as well. Even in a function in a module, |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Okay I finished the last piece and cleaned up the code a bit. Now we have some very consistent behavior for
This breaks the behavior introduced by pep 709 that
Let me know if there are missing pieces that I don't know of. |
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.
This looks good. Thanks for your perseverance.
last chance for comments.
I'm going to merge this in 12 hours or so, if no one objects.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…te locals() "PEP 667: Consistent views of namespaces" caused locals() to be inconsistent between uses since it is now created afresh every time you invoke it and writes to it are dropped. `sys._getframe().f_locals` is equivalent but preserves writes (it doesn't create a new dict) and unfortunately doesn't help at all as it's documented to be a private implementation detail of CPython that "should be used for internal and specialized purposes only". Work around this by saving locals to a variable reference and both passing it into runctx and reusing it in lookups of the result. This works okay for both new and older versions of python. Bug: python/cpython#115153
…te locals() "PEP 667: Consistent views of namespaces" caused locals() to be inconsistent between uses since it is now created afresh every time you invoke it and writes to it are dropped. `sys._getframe().f_locals` is equivalent but preserves writes (it doesn't create a new dict) and unfortunately doesn't help at all as it's documented to be a private implementation detail of CPython that "should be used for internal and specialized purposes only". Work around this by saving locals to a variable reference and both passing it into runctx and reusing it in lookups of the result. This works okay for both new and older versions of python. Per the documentation for locals(): > The contents of this dictionary should not be modified; changes may > not affect the values of local and free variables used by the > interpreter. So... lesson learned? :) This was introduced in commit c34ee37; before that, we still used locals() but only to pass local variables *in*. Bug: python/cpython#115153
There was an error while loading. Please reload this page.
|
FYI, docs are missing here: https://docs.python.org/3.13/c-api/reflection.html The back-compat functions were causing a few destructors to not be called properly in three tests in pybind11; switching to the new functions fixed it, though. Not sure if that's expected. I believe it’s because the back compat function for eval frame locals is basically the same as the new function and returns a new reference. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…te locals() "PEP 667: Consistent views of namespaces" caused locals() to be inconsistent between uses since it is now created afresh every time you invoke it and writes to it are dropped. `sys._getframe().f_locals` is equivalent but preserves writes (it doesn't create a new dict) and unfortunately doesn't help at all as it's documented to be a private implementation detail of CPython that "should be used for internal and specialized purposes only". Work around this by saving locals to a variable reference and both passing it into runctx and reusing it in lookups of the result. This works okay for both new and older versions of python. Per the documentation for locals(): > The contents of this dictionary should not be modified; changes may > not affect the values of local and free variables used by the > interpreter. So... lesson learned? :) This was introduced in commit c34ee37; before that, we still used locals() but only to pass local variables *in*. Bug: python/cpython#115153
…te locals() "PEP 667: Consistent views of namespaces" caused locals() to be inconsistent between uses since it is now created afresh every time you invoke it and writes to it are dropped. `sys._getframe().f_locals` is equivalent but preserves writes (it doesn't create a new dict) and unfortunately doesn't help at all as it's documented to be a private implementation detail of CPython that "should be used for internal and specialized purposes only". Work around this by saving locals to a variable reference and both passing it into runctx and reusing it in lookups of the result. This works okay for both new and older versions of python. Per the documentation for locals(): > The contents of this dictionary should not be modified; changes may > not affect the values of local and free variables used by the > interpreter. So... lesson learned? :) This was introduced in commit c34ee37; before that, we still used locals() but only to pass local variables *in*. Bug: python/cpython#115153
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.