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
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.
[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
>
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.
>
>
[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
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
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
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
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"
[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 ()
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,
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
[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
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
[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,
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():
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
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
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,
>>
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`
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
[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
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
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
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
> >
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
>
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
[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?
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
29 matches
Mail list logo