Makes sense. Thanks for the clarification!

On Wed, Jan 1, 2020 at 1:30 AM Nick Coghlan <ncogh...@gmail.com> wrote:

> On Wed, 1 Jan 2020 at 10:42, Yonatan Zunger <zun...@humu.com> wrote:
> >
> > Thanks for writing this up, Nick!
> >
> > My main question is about the remaining difference between semantics at
> the class/module versus function level: is it worth the additional
> cognitive complexity to have the class/module behavior be different from
> the function behavior?
>
> Mutating values through locals() has long worked at class and module
> scope, and folks rely on that often enough that we don't want to break
> their code. Correctly supporting mutation via locals() also falls
> naturally out of the runtime semantics of those scopes (at module
> scope, locals() returns the same namespace as globals() does, while at
> class scope it returns the same namespace as will eventually be passed
> to the metaclass to create the new class object).
>
> By contrast, mutation via locals() at function scope hasn't worked
> consistently since fast locals were introduced, and that predates even
> statically nested scopes (I went trawling through the repo history to
> try to work out when they were first added, and made it as far as
> "some time before 1997, since [1] changed how they worked to make them
> faster, but was replacing an even older list-based mechanism").
>
> Cheers,
> Nick.
>
> [1]
> https://github.com/python/cpython/commit/f3e85a0356e679ed9ff8d13236ff8e9f77a9fd0b#diff-f1de0b7194da5b0cdf48379eca8678d7
>
> --
> Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/S3MOFZMX6NWUCNL33ROALUNJDGN3YQ5H/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to