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 Python.
>
> There a
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
> existing reference in the lo
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
> > longstanding precedent that the try/except
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 that block?
[Tim Peters]
I rea
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 duration would vanish when
[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 vari
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
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` statement:
with local('m1', 'm2'):
m
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,
>>
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 trailing () is a little ugly, but the semantics are
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 different syntax:
c = (lambda a=3, b=4: a*b)()
The trailin
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():
b
[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, but the semantics are
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 different syntax:
>>
>> c = (lambda a=3, b=4: a*
[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 has been declared globa
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 there is demand for this, how about just introduc
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,
[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, but
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" via lambdas has become ludicrously diffi
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 handful of specific, explic
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 wrote:
> > As covered most recently i
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 ;-
[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 it is now, these ki
On 2018-04-29 10:20 PM, Ethan Furman wrote:
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
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.
>
> with sublocal(a=6):
>
[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
> g()
> g()
>
> should
[Tim]
>> ...
>> Worm around that too, then going back to the example at the top, if
>> the manager's
>>
>> locals().update(_locals)
>>
>> had the intended effect, it would end up restoring `b` to 2 too, yes?
>> The only names that "should be" restored are the names in the `kws`
>> dict.
[D
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. Sorry
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 reasonabl
I really liked the syntax that mimicked lambda even if I find it verbose :
a = local x=1, y=2: x + y + 3
Even if I still prefer the postfix syntax :
a = x + 3 where x = 2
About scheme "let" vs "let*", the paralel in Python is :
a, b, c = 5, a+1, 2 # let syntax
a = 5; b = a+1; c = 2 # let* synt
30 matches
Mail list logo