Re: [Python-ideas] Sublocal scoping at its simplest

2018-04-29 Thread Greg Ewing
Chris Angelico wrote: 1) Bind the caught exception to a sublocal 'e' 2) Execute the suite, with the reference to 'e' seeing the sublocal 3) Set the sublocal e to None 4) Unbind the sublocal e At the unindent, the sublocal name will vanish, and the original 'e' will reappear. That's a

Re: [Python-ideas] Should __builtins__ have some kind of pass-through print function, for debugging?

2018-04-29 Thread Greg Ewing
Nathaniel Smith wrote: It looks like my client used "font-family: monospace", maybe yours only understands or something? Hmmm, looking at the message source, it does indeed specify monospace. It seems the version of Thunderbird I'm using does a spectacularly bad job of interpreting HTML.

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Tim Peters
[Soni L. ] > That ain't shadow. That is dynamic scoping. I don't believe either term is technically accurate, but don't really care. > Shadowing is something different: > > def f(): > a = 42 > def g(): > print(a) > local a: > a = 43 >

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread David Mertz
On Sun, Apr 29, 2018 at 9:28 PM, Tim Peters wrote: > [David Mertz ] > > Ooops. My proof [of] anti-concept has a flaw. It only "shadows" names > that > > already exist. Presumably that's the wrong idea, but it's easy enough to > > change if desired. > >

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Tim Peters
[David Mertz ] > Ooops. My proof on anti-concept has a flaw. It only "shadows" names that > already exist. Presumably that's the wrong idea, but it's easy enough to > change if desired. Even in the very early days when Python's runtime was more relentlessly simple-minded than

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Ethan Furman
On 04/29/2018 01:20 PM, Tim Peters wrote: So, e.g., """ a = 42 def showa(): print(a) def run(): global a local a: # assuming this existed a = 43 showa() showa() """ would print 43 and then 42. Which makes "local a:" sound senseless on the face of it

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread David Mertz
Ooops. My proof on anti-concept has a flaw. It only "shadows" names that already exist. Presumably that's the wrong idea, but it's easy enough to change if desired. On Sun, Apr 29, 2018 at 5:24 PM, Paul Moore wrote: > On 29 April 2018 at 21:20, Tim Peters

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Paul Moore
On 29 April 2018 at 21:20, Tim Peters 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

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Chris Angelico
On Mon, Apr 30, 2018 at 6:45 AM, Tim Peters wrote: > [Chris Angelico ] >> So maybe the effective semantics should be: >> >> >>> (lambda a=3: (lambda b=a+1: (a, b))())() >> (3, 4) > > Almost, but by that point the idea that this is already "easily > spelled"

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Tim Peters
[Tim] Then `c` is 12, but `a` is still 1 and `b` is still 2. Same thing in the end: c = local(a=3, b=4, a*b) [Nikolaus Rath ] >>> I think this can be done already with slighly different syntax: >>> >>> c = (lambda a=3, b=4: a*b)() >>> >>> The trailing ()

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread David Mertz
This doesn't address the fact no one actually needs it. But if we WANTED a sublocal() context manager, we could spell it something like this: In [42]: @contextmanager ...: def sublocal(**kws): ...: _locals = locals().copy() ...: _globals = globals().copy() ...: for k,

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Mikhail V
On Sun, Apr 29, 2018 at 7:22 PM, Mikhail V wrote: > On Sun, Apr 29, 2018 at 3:30 AM, Tim Peters wrote: > >> Time to note another subtlety: people don't _really_ want "a new >> scope" in Python. If they did, then _every_ name appearing in a > If

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Tim Peters
[Ethan Furman ] > If we need a sublocal scope, I think the most Pythonic* route to have it > would be: > > with sublocal(): > blah blah > > which would act just like local/global does now: > > - any assignment creates a new variable > - unless that variable

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Chris Angelico
On Mon, Apr 30, 2018 at 5:55 AM, Tim Peters wrote: > [Tim] >>> Then `c` is 12, but `a` is still 1 and `b` is still 2. Same thing in the >>> end: >>> >>> c = local(a=3, b=4, a*b) > > [Nikolaus Rath ] >> I think this can be done already with slighly

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Tim Peters
[Tim] >> Then `c` is 12, but `a` is still 1 and `b` is still 2. Same thing in the >> end: >> >> c = local(a=3, b=4, a*b) [Nikolaus Rath ] > I think this can be done already with slighly different syntax: > > c = (lambda a=3, b=4: a*b)() > > The trailing () is a little ugly,

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Ethan Furman
On 04/28/2018 10:16 AM, Tim Peters wrote: ... but do realize that since PEP 572 dropped any notion of sublocal scopes, that recurring issue remains wholly unaddressed regardless. If we need a sublocal scope, I think the most Pythonic* route to have it would be: with sublocal():

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Soni L.
On 2018-04-29 04:17 PM, Nikolaus Rath wrote: On Apr 27 2018, Tim Peters wrote: Then `c` is 12, but `a` is still 1 and `b` is still 2. Same thing in the end: c = local(a=3, b=4, a*b) I think this can be done already with slighly

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Nikolaus Rath
On Apr 27 2018, Tim Peters wrote: > Then `c` is 12, but `a` is still 1 and `b` is still 2. Same thing in the end: > > c = local(a=3, b=4, a*b) I think this can be done already with slighly different syntax: c = (lambda a=3, b=4: a*b)() The

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread MRAB
On 2018-04-29 18:01, Tim Peters wrote: [Tim] >> ... >> This is the kind of code about which there have been background >> complaints "forever": >> >> m1 = regexp1.match(line) >> m2 = regexp2.match(iine) >> if m1 and m2: >> do all sorts of stuff with m1 and/or m2, >>

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Kirill Balunov
2018-04-29 17:52 GMT+03:00 MRAB : > > >> How about these: > > local m1, m2: > m1 = regexp1.match(line) > m2 = regexp2.match(line): > if m1 and m2: > ... > Is it possible to do the same thing, but with the help of `with`

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Ethan Furman
On 04/27/2018 07:37 PM, Tim Peters wrote: Idea: introduce a "local" pseudo-function to capture the idea of initialized names with limited scope. Note: the thing I'm most interested in isn't debates, but in whether this would be of real use in real code. I keep going back and forth on the

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Tim Peters
[Tim] >> ... >> This is the kind of code about which there have been background >> complaints "forever": >> >> m1 = regexp1.match(line) >> m2 = regexp2.match(iine) >> if m1 and m2: >> do all sorts of stuff with m1 and/or m2, >> including perhaps modifying local

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Mikhail V
On Sun, Apr 29, 2018 at 3:30 AM, Tim Peters wrote: > > """ > Time to note another subtlety: people don't _really_ want "a new > scope" in Python. If they did, then _every_ name appearing in a > binding context (assignment statement target, `for` target, ...) for > the

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread MRAB
On 2018-04-29 07:57, Tim Peters wrote: [Tim Delaney ] My big concern here involves the: if local(m = re.match(regexp, line)): print(m.group(0)) example. The entire block needs to be implicitly local for that to work - what happens if I assign a new name in

Re: [Python-ideas] Sublocal scoping at its simplest

2018-04-29 Thread Nick Coghlan
On 29 April 2018 at 21:24, Chris Angelico wrote: > On Sun, Apr 29, 2018 at 6:03 PM, Nick Coghlan wrote: > > The challenge with doing this implicitly is that there's no indication > > whatsoever that the two "e"'s are different, especially given the > >

Re: [Python-ideas] Sublocal scoping at its simplest

2018-04-29 Thread Chris Angelico
On Sun, Apr 29, 2018 at 6:03 PM, Nick Coghlan wrote: > The challenge with doing this implicitly is that there's no indication > whatsoever that the two "e"'s are different, especially given the > longstanding precedent that the try/except level one will overwrite any >

Re: [Python-ideas] Sublocal scoping at its simplest

2018-04-29 Thread Nick Coghlan
On 29 April 2018 at 13:14, Chris Angelico wrote: > There's been a lot of talk about sublocal scopes, within and without > the context of PEP 572. I'd like to propose what I believe is the > simplest form of sublocal scopes, and use it to simplify one specific > special case in

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Tim Peters
[Tim Delaney ] >>> My big concern here involves the: >>> >>> if local(m = re.match(regexp, line)): >>> print(m.group(0)) >>> >>> example. The entire block needs to be implicitly local for that to work >>> - >>> what happens if I assign a new name in that block?

Re: [Python-ideas] A "local" pseudo-function

2018-04-29 Thread Tim Peters
Tim] Peters wrote: >> The points to using function-call-like syntax were already covered >> ("nothing syntactically new to learn there", [Greg Ewing] [> The trouble is that one usually expects "nothing syntactically > new" to imply "nothing semantically new" as well, which is very > far from the