gh-74929: Implement PEP 667 by gaogaotiantian · Pull Request #115153 · python/cpython

added 4 commits

February 6, 2024 23:15

markshannon

@gaogaotiantian

@gaogaotiantian

@gaogaotiantian

markshannon

markshannon

@gaogaotiantian

SonicField pushed a commit to SonicField/cpython that referenced this pull request

May 8, 2024

eli-schwartz added a commit to eli-schwartz/meson that referenced this pull request

May 13, 2024
…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

eli-schwartz added a commit to eli-schwartz/meson that referenced this pull request

May 13, 2024
…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

eli-schwartz added a commit to eli-schwartz/meson that referenced this pull request

Jun 23, 2024
…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

Volker-Weissmann pushed a commit to Volker-Weissmann/meson that referenced this pull request

May 1, 2025
…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