[Python-ideas] A "local" pseudo-function
Paul Moore
p.f.moore at gmail.com
Sun Apr 29 17:24:17 EDT 2018
On 29 April 2018 at 21:20, Tim Peters <tim.peters at gmail.com> wrote:
> As covered most recently in an exchange with Tim Delaney, best I can
> tell absolutely nobody has wanted that. By "sublocal scope" they
> don't mean a full-fledged new scope at all, but a kind of limited
> "shadowing" of a handful of specific, explicitly given names. It acts
> like a context manager, if there were a way to clearly spell
>
> save the current state of these specific identifiers at the start (& I
> couldn't care less whether they're local, nonlocal, or global - I
> don't know & don't care)
>
> then execute the code exactly as if this gimmick had never been used
>
> then, at the end, restore the specific identifier states we saved
> at the start
So maybe adding such a primitive (maybe something live states =
sys.get_variable_state('a', 'b', 'c') and
sys.set_variable_state(states)) would be useful? Of course, we've
moved away from real use cases and back to theoretical arguments now,
so it's entirely possible that doing so would only solve problems that
no-one actually has... David Mertz' sublocal context manager would be
a good prototype of such a thing - at least good enough to demonstrate
that it's of no benefit in practice <wink>
Paul
More information about the Python-ideas
mailing list