[Python-Dev] PEP 558: Defined semantics for locals()

2021-07-18 Thread Nick Coghlan
Hi folks, It's been a long time coming, but I've finally made enough progress on the reference implementation that I think it's time to ask Nathaniel to pronounce on the current iteration of PEP 558 (Defined semantics for locals()). The rendered version is up at

[Python-Dev] PEP 558: Defined semantics for locals() (December 2019 edition)

2019-12-30 Thread Nick Coghlan
Hi folks, I've finally updated PEP 558 and it's reference implementation based on Nathaniel's feedback back in May. The latest version of the PEP can now be found at https://www.python.org/dev/peps/pep-0558/, and I've created a discussion thread on Discourse:

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-30 Thread Nick Coghlan
On Fri., 31 May 2019, 5:20 am Xavier de Gaye, wrote: > Currently f_locals is documented as readonly [1]. > Read-only in the sense that you can't rebind it to point to a different object - the dict it points to is mutable. > The PEP says: > > * "Don't change what isn't broken": the current

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-30 Thread Xavier de Gaye
Currently f_locals is documented as readonly [1]. The PEP says: * "Don't change what isn't broken": the current tracing mode problems are caused by a requirement that's specific to tracing mode (support for external rebinding of function local variable references), so it made sense to also

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-28 Thread Nick Coghlan
On Sun, 26 May 2019 at 00:37, Guido van Rossum wrote: > > This looks great. > > I only have two nits with the text. > > First, why is the snapshot called a "dynamic snapshot"? What exactly is > dynamic about it? The dynamic part comes in if you call locals() twice: because it returns the same

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-28 Thread Steve Holden
I'm guessing the reason is to remove the overhead of keeping the dictionary up to date during function execution when no Python code needs access to it. On Mon, May 27, 2019 at 8:10 PM Richard Damon wrote: > On 5/27/19 2:05 PM, Terry Reedy wrote: > > On 5/27/2019 9:52 AM, Richard Damon wrote:

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-27 Thread Richard Damon
On 5/27/19 2:05 PM, Terry Reedy wrote: > On 5/27/2019 9:52 AM, Richard Damon wrote: >> On 5/27/19 9:12 AM, Terry Reedy wrote: > >>> I believe that the situation is or can be thought of as this: there is >>> exactly 1 function locals dict. > > per function invocation, or more generally, as Guido

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-27 Thread Terry Reedy
On 5/27/2019 9:52 AM, Richard Damon wrote: On 5/27/19 9:12 AM, Terry Reedy wrote: I believe that the situation is or can be thought of as this: there is exactly 1 function locals dict. per function invocation, or more generally, as Guido said, per stack frame. This part is obvious to me,

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-27 Thread Paul Moore
On Mon, 27 May 2019 at 16:11, Guido van Rossum wrote: > > No, there's only one locals() dict *per stack frame*. So no worries about > concurrency. Again, if the PEP is about formalising the behaviour as language mandated, this is worth documenting explicitly. Paul

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-27 Thread Guido van Rossum
No, there's only one locals() dict *per stack frame*. So no worries about concurrency. On Mon, May 27, 2019 at 6:54 AM Richard Damon wrote: > On 5/27/19 9:12 AM, Terry Reedy wrote: > > On 5/27/2019 3:18 AM, Greg Ewing wrote: > >> Chris Angelico wrote: > >>> Except that it does. After calling

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-27 Thread Richard Damon
On 5/27/19 9:12 AM, Terry Reedy wrote: > On 5/27/2019 3:18 AM, Greg Ewing wrote: >> Chris Angelico wrote: >>> Except that it does. After calling locals() a second time, the result >>> of the *first* call will be updated to reflect changes. >> >> Yeow. That's *really* unintuitive. There had better

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-26 Thread Steven D'Aprano
On Sun, May 26, 2019 at 09:20:53PM +1000, Chris Angelico wrote: > Sure, but this PEP is all about defining things that weren't > previously defined, so I wanted to clarify intent rather than current > behaviour. As I understand it, the intent is to: - fix some annoyances/bugs involved when you

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-26 Thread Paul Moore
On Sun, 26 May 2019 at 12:23, Chris Angelico wrote: > > On Sun, May 26, 2019 at 8:07 PM Steven D'Aprano wrote: > > On Sun, May 26, 2019 at 08:44:33AM +1000, Chris Angelico wrote: > > > > > From my reading of the description, you could also "assert a is b" - > > > is that correct? > > > > Yes,

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-26 Thread Chris Angelico
On Sun, May 26, 2019 at 8:07 PM Steven D'Aprano wrote: > On Sun, May 26, 2019 at 08:44:33AM +1000, Chris Angelico wrote: > > > From my reading of the description, you could also "assert a is b" - > > is that correct? > > Yes, that's already the behaviour. > > py> def demo(): > ... a =

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-26 Thread Steven D'Aprano
On Sun, May 26, 2019 at 08:04:11PM +1000, Steven D'Aprano wrote: > Richard, your email seems to have introduced a spurious "SPAM" label [...] > edit the subject line to remove the > label? Thanks. I've done so for this response Oops. Done now. -- Steven

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-26 Thread Steven D'Aprano
(And this time I will remember to remove the SPAM label...) On Sun, May 26, 2019 at 08:44:33AM +1000, Chris Angelico wrote: > From my reading of the description, you could also "assert a is b" - > is that correct? Yes, that's already the behaviour. py> def demo(): ... a = locals() ...

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-25 Thread Guido van Rossum
That's a good fine point that the PEP could call out, but just adding "dynamic" in front of "snapshot" everywhere doesn't tell me any of that. Given that the code calling locals() must of necessity live in the same function body (except for the special case of trace functions), I don't think that

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-25 Thread Nathaniel Smith
On Sat, May 25, 2019, 07:38 Guido van Rossum wrote: > This looks great. > > I only have two nits with the text. > > First, why is the snapshot called a "dynamic snapshot"? What exactly is > dynamic about it? > It's dynamic in that it can spontaneously change when certain other events happen.

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-25 Thread Terry Reedy
On 5/25/2019 10:36 AM, Guido van Rossum wrote: This looks great. I agree. I understand and have tried to explain normal operation multiple times. The proposed new doc looks better than anything I ever wrote. (I never even thought about locals() with tracing on.) The improved clarity

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-25 Thread Guido van Rossum
This looks great. I only have two nits with the text. First, why is the snapshot called a "dynamic snapshot"? What exactly is dynamic about it? Second, you use the word "mapping" a lot. Would you mind changing that to "mapping object" in most places? Especially in the phrase "each call to

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-25 Thread Armin Rigo
Hi, On Thu, 23 May 2019 at 17:28, Steve Dower wrote: > On 23May2019 0636, Nick Coghlan wrote: > > However, I think the PR does show that the proposed technique can be > > implemented without too much additional code complexity, and will > > hopefully be adaptable for all implementations that

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-23 Thread Steve Dower
On 23May2019 0636, Nick Coghlan wrote: However, I think the PR does show that the proposed technique can be implemented without too much additional code complexity, and will hopefully be adaptable for all implementations that emulate the frame API at all. Much excitement! One of the things I

Re: [Python-Dev] PEP 558: Defined semantics for locals()

2019-05-23 Thread Nick Coghlan
On Wed, 22 May 2019 at 00:51, Nick Coghlan wrote: > P.S. I'm away this weekend, so I expect the reference implementation > to be done late next week, and I'd be submitting the PEP to Nathaniel > for formal pronouncement at that point. However, I'm posting this > thread now so that there's more

[Python-Dev] PEP 558: Defined semantics for locals()

2019-05-21 Thread Nick Coghlan
Hi folks, After a couple of years hiatus, I finally got back to working on the reference implementation for PEP 558, my proposal to resolve some weird interactions between closures and trace functions in CPython by formally defining the expected semantics of the locals() builtin at function