[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread Steven D'Aprano
On Sun, Dec 04, 2022 at 01:34:13PM -0800, Bruce Leban wrote: > I agree with most criticism of this proposal, although I'll note that > the one place where I'd like something like this is at top level. I > often write something like this at top level: > > __part1 = (some calculation) > __part2

[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread Chris Angelico
On Mon, 5 Dec 2022 at 08:34, Bruce Leban wrote: > > > I can put that in a function which still leaves the function in scope: > > def __create_thing(): > part1 = (some calculation) > part2 = (some other calculation) > return combine(part1, part2) > THING = __create_thing() > > If we had

[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread Bruce Leban
On Sun, Dec 4, 2022 at 11:08 AM Chris Angelico wrote: > > > You're not the first to try to use globals() for this, but it means > that the context manager works ONLY at top-level. > I agree with most criticism of this proposal, although I'll note that the one place where I'd like something like

[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread Rob Cliffe via Python-ideas
On 04/12/2022 17:08, Chris Angelico wrote: On Mon, 5 Dec 2022 at 04:07, Rob Cliffe via Python-ideas wrote: On 30/11/2022 20:27, Anony Mous wrote: Danceswithmice wrote: The idea is that YOU write "local:", and the interpreter, without you ever seeing it, promotes that into a hidden funct

[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread Chris Angelico
On Mon, 5 Dec 2022 at 06:24, David Mertz, Ph.D. wrote: > > On Sun, Dec 4, 2022, 2:08 PM Chris Angelico wrote: >> >> You're not the first to try to use globals() for this, but it means that the >> context manager works ONLY at top-level. > > > True. I know that. But if you're inside a function, y

[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread David Mertz, Ph.D.
On Sun, Dec 4, 2022, 2:08 PM Chris Angelico wrote: > You're not the first to try to use globals() for this, but it means that > the context manager works ONLY at top-level. True. I know that. But if you're inside a function, you already have scope containment, so the issue feels like "so what?"

[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread Chris Angelico
On Mon, 5 Dec 2022 at 06:04, David Mertz, Ph.D. wrote: > > Like most commenters, I think the whole "create an anonymous function then > call it" scoping thing is too complex and has too many edge cases to be a > good idea. > > That said, I decided to play around with what I can do to serve the g

[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread David Mertz, Ph.D.
Like most commenters, I think the whole "create an anonymous function then call it" scoping thing is too complex and has too many edge cases to be a good idea. That said, I decided to play around with what I can do to serve the general purpose within existing Python: >>> @contextmanager ... def l

[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread Chris Angelico
On Mon, 5 Dec 2022 at 04:07, Rob Cliffe via Python-ideas wrote: > > > > On 30/11/2022 20:27, Anony Mous wrote: > > Danceswithmice wrote: > > > > > > > > The idea is that YOU write "local:", and the interpreter, without you > > ever seeing it, promotes that into a hidden function with a hidden > >

[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread Rob Cliffe via Python-ideas
On 30/11/2022 20:27, Anony Mous wrote: Danceswithmice wrote: The idea is that YOU write "local:", and the interpreter, without you ever seeing it, promotes that into a hidden function with a hidden name and a hidden call. --- p.f.moore wrote: > That would make "return" in the local sco