On 2018-04-29 07:57, Tim Peters wrote:
[Tim Delaney <timothy.c.dela...@gmail.com>]
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 really don't know what you're asking there.  Can you make it
concrete?  If, e.g., you're asking what happens if this appeared after
the `print`:

        x = 3.14

then the answer is "the same as what would happen if `local` had not
been used".  We can't know what that is without context, though.
Maybe x is global.  Maybe x was declared nonlocal earlier.  Maybe it's
function-local. ...

[Tim D]
That's exactly what I was asking, and as I understand what you're saying, we
would have a local name m available in the indented block which went away
when the block ended, but any names modified in the block are not local to
the block. That seems likely to be a source of errors.

If you what you _want_ is a genuinely new scope, yes.  But no actual
use cases so far wanted that at all.

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 variables
         and/or global variables
         and/or nonlocal variables

The complaints are of two distinct kinds:

1. "I want to compute m1 and m2 _in_ the `if` test".

2. "I don't want these temp names (m1 and m2) accidentally
    conflicting with local names already in scope - if these names
    already exist, I want the temp names to shadow their
    current bindings until the `if` structure is done".

So,

     if local(m1=regexp1.match(line),
               m2 = regexp2.match(iine),
               m1 and m2):

intends to address both complaints via means embarrassingly obvious to
the most casual observer ;-)

How about these:

    local m1, m2:
        m1 = regexp1.match(line)
        m2 = regexp2.match(line):
        if m1 and m2:
            ...


    local m1, m2:

        if (m1 := regexp1.match(line)) and (m2 := regexp2.match(line)):

            ...

    local m1=regexp1.match(line), m2=regexp2.match(line):
        if m1 and m2:
            ...

?

[snip]
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to