[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-26 Thread Guido van Rossum
On Thu, Aug 26, 2021 at 5:29 PM Nick Coghlan wrote: > [snip] > For the main topic of PEP 667 (reducing the cache consistency question to > purely a matter of PyEval_GetLocals() compatibility), I think I can see a > way to make the extra code complexity of the 5 new custom accessory types >

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-26 Thread Nick Coghlan
On Fri, 27 Aug 2021, 2:33 am Guido van Rossum, wrote: > On Thu, Aug 26, 2021 at 2:31 AM Nick Coghlan wrote: > >> On Thu, 26 Aug 2021 at 18:29, Nick Coghlan wrote: >> [Guido wrote] >> > > PS. The mapping from varname to position should be on the code >> object, not on the frame. This is how

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-26 Thread Guido van Rossum
On Thu, Aug 26, 2021 at 2:31 AM Nick Coghlan wrote: > On Thu, 26 Aug 2021 at 18:29, Nick Coghlan wrote: > [Guido wrote] > > > PS. The mapping from varname to position should be on the code object, > not on the frame. This is how Mark does it (though his implementation would > need to be

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-26 Thread Guido van Rossum
On Thu, Aug 26, 2021 at 2:40 AM Nick Coghlan wrote: > [snip] > An unrelated issue that came up while working on that update is > something that affects both PEPs: calling "proxy.clear()" is *super > weird* if we make it work the same way as PyEval_LocalsToFast() works > today. Specifically, it

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-26 Thread Guido van Rossum
On Thu, Aug 26, 2021 at 1:29 AM Nick Coghlan wrote: > On Mon, 23 Aug 2021 at 13:07, Guido van Rossum wrote: > > But... I also care about backwards compatibility, and I have a crazy > idea for making PyEval_GetLocals() work in a useful manner without > compromising the behavior of the f_locals

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-26 Thread Nick Coghlan
On Tue, 24 Aug 2021 at 01:57, Guido van Rossum wrote: > On Mon, Aug 23, 2021 at 8:46 AM Mark Shannon wrote: >> Can we avoid describing the C structs in any of these PEPs? >> >> It confuses readers having Python attributes and "C-level attributes" >> (C struct fields?). >> It also restricts the

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-26 Thread Nick Coghlan
On Thu, 26 Aug 2021 at 18:29, Nick Coghlan wrote: [Guido wrote] > > PS. The mapping from varname to position should be on the code object, not > > on the frame. This is how Mark does it (though his implementation would > > need to be extended to take cells into account). > > It's taking cells

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-26 Thread Nick Coghlan
On Mon, 23 Aug 2021 at 13:07, Guido van Rossum wrote: > But... I also care about backwards compatibility, and I have a crazy idea for > making PyEval_GetLocals() work in a useful manner without compromising the > behavior of the f_locals proxy: > > - Let's start your idea of using the C-level

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-24 Thread MRAB
On 2021-08-24 17:55, Patrick Reader wrote: On 24/08/2021 06:27, Steven D'Aprano wrote: Wouldn't that attempt to resolve global y, rather than local y? Unless there is a change to the current behaviour of the compiler, I think you need to fool the compiler: if False: y = 0 # anywhere

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-24 Thread Patrick Reader
On 24/08/2021 06:27, Steven D'Aprano wrote: > Wouldn't that attempt to resolve global y, rather than local y? Unless > there is a change to the current behaviour of the compiler, I think you > need to fool the compiler: > >if False: y = 0 # anywhere inside the function is okay Time to

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-23 Thread Guido van Rossum
I apologize. This does indeed not work. What does work, however, is setting a variable from a tracing function. There is magic in the tracing machinery that writes back the variables to the frame when the tracing function returns. This causes the bug referenced as [1] in both PEPs, and both

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-23 Thread Steven D'Aprano
On Fri, Aug 20, 2021 at 04:22:56PM +0100, Mark Shannon wrote: > Hi all, > > I have submitted PEP 667 as an alternative to PEP 558. > https://www.python.org/dev/peps/pep-0667 Specification has a code snippet: def test(): x = 1 l()['x'] = 2 l()['y'] = 4

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-23 Thread Steven D'Aprano
On Sat, Aug 21, 2021 at 05:46:52PM -0700, Guido van Rossum wrote: > Hopefully anyone is still reading python-dev. I am :-) [...] > Everything here is about locals() and f_locals in *function scope*. (I use > f_locals to refer to the f_locals field of frame objects as seen from > Python code.)

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-23 Thread Gregory P. Smith
Just adding a datapoint, searching our internal codebase at work, I only found two things that I'd consider to be uses of PyEval_GetLocals() outside of CPython itself: https://github.com/earwig/mwparserfromhell/blob/develop/src/mwparserfromhell/parser/ctokenizer/tokenizer.c#L220

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-23 Thread Guido van Rossum
On Mon, Aug 23, 2021 at 8:46 AM Mark Shannon wrote: > Hi Guido, > > On 23/08/2021 3:53 pm, Guido van Rossum wrote: > > On Mon, Aug 23, 2021 at 4:38 AM Mark Shannon > > wrote: > > > > Hi Nick, > > > > On 22/08/2021 4:51 am, Nick Coghlan wrote: > > > > > If

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-23 Thread Mark Shannon
Hi Guido, On 23/08/2021 3:53 pm, Guido van Rossum wrote: On Mon, Aug 23, 2021 at 4:38 AM Mark Shannon > wrote: Hi Nick, On 22/08/2021 4:51 am, Nick Coghlan wrote: > If Mark's claim that PyEval_GetLocals() could not be fixed was true then > I would

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-23 Thread Guido van Rossum
On Mon, Aug 23, 2021 at 4:38 AM Mark Shannon wrote: > Hi Nick, > > On 22/08/2021 4:51 am, Nick Coghlan wrote: > > > If Mark's claim that PyEval_GetLocals() could not be fixed was true then > > I would be more sympathetic to his proposal, but I know it isn't true, > > because it still works fine

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-23 Thread Mark Shannon
Hi Nick, On 22/08/2021 4:51 am, Nick Coghlan wrote: On Sun, 22 Aug 2021, 10:47 am Guido van Rossum, > wrote: Hopefully anyone is still reading python-dev. I'm going to try to summarize the differences between the two proposals, even though Mark already

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-22 Thread Guido van Rossum
On Sat, Aug 21, 2021 at 8:52 PM Nick Coghlan wrote: > > On Sun, 22 Aug 2021, 10:47 am Guido van Rossum, wrote: > >> >> Everything here is about locals() and f_locals in *function scope*. (I >> use f_locals to refer to the f_locals field of frame objects as seen from >> Python code.) And in

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-21 Thread Nick Coghlan
On Sun, 22 Aug 2021, 10:47 am Guido van Rossum, wrote: > Hopefully anyone is still reading python-dev. > > I'm going to try to summarize the differences between the two proposals, > even though Mark already did so in his PEP. But I'd like to start by > calling out the key point of contention. >

[Python-Dev] Re: PEP 667: Consistent views of namespaces

2021-08-21 Thread Guido van Rossum
Hopefully anyone is still reading python-dev. I'm going to try to summarize the differences between the two proposals, even though Mark already did so in his PEP. But I'd like to start by calling out the key point of contention. Everything here is about locals() and f_locals in *function scope*.