Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-11 Thread Nick Coghlan
On 11 June 2018 at 04:35, Juancarlo Añez wrote: > > As the PEP author, that's your job. >> > > I started writing the PEP, and I found an interesting example: > > if not (m := re.match(r'^(\d+)-(\d+)$', identifier): > raise ValueError('f{identifier} is not a valid identifier') > pr

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-10 Thread Juancarlo Añez
> As the PEP author, that's your job. > I started writing the PEP, and I found an interesting example: if not (m := re.match(r'^(\d+)-(\d+)$', identifier): raise ValueError('f{identifier} is not a valid identifier') print(f'first part is {m.group(1)}') print(f'first part is {m

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-10 Thread Steven D'Aprano
On Sun, Jun 10, 2018 at 08:08:13AM -0400, Juancarlo Añez wrote: > > while (condition := expression) as flag: > > ... > > > > Ah! Are the parenthesis necessary there? It's your PEP, you tell us. > > Accepting "while/if as name" would remove much (but not all) of the > > motivation f

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-10 Thread Chris Angelico
On Sun, Jun 10, 2018 at 10:08 PM, Juancarlo Añez wrote: > > There can be cases in which combining both syntaxes is useful: > > x = None > while compute(x := v for v in next_series_value(x)) as comp: > ... > x = comp Why not just: while comp := compute(x := v for v in next_series_value(x)

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-10 Thread Juancarlo Añez
> The only difference is that the `except` block implicitly unbinds the > variable when the block ends. > Mmmm. Good to know, because that means that the semantics are the same, except... > > while (condition := expression) as flag: > ... > Ah! Are the parenthesis necessary there?

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-09 Thread Steven D'Aprano
On Sat, Jun 09, 2018 at 09:17:37AM -0400, Juancarlo Añez wrote: > > Do you mean the context manager semantics of with statements? As in, > > calling the __enter__ and __exit__ method? > > > > No. Just the scope of the variables introduced, which is different in `with > as` and `except as`. They a

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-09 Thread Juancarlo Añez
> Do you mean the context manager semantics of with statements? As in, > calling the __enter__ and __exit__ method? > No. Just the scope of the variables introduced, which is different in `with as` and `except as`. > Please make sure you are very familiar with PEP 572 before you do, and > expect

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-09 Thread Steven D'Aprano
On Sat, Jun 09, 2018 at 08:43:47AM -0400, Juancarlo Añez wrote: > Hello @here, > > Is there a guide about writing (and publishing) PEPs? https://www.python.org/dev/peps/pep-0001/ > I'd like to write one on `while expre as v: ...` using the context > semantics of `with expr as v` (not `except E

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-09 Thread Jeroen Demeyer
On 2018-06-09 14:43, Juancarlo Añez wrote: Is there a guide about writing (and publishing) PEPs? https://www.python.org/dev/peps/pep-0001/ ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code

[Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-09 Thread Juancarlo Añez
Hello @here, Is there a guide about writing (and publishing) PEPs? I'd like to write one on `while expre as v: ...` using the context semantics of `with expr as v` (not `except E as e`). Cheers, ___ Python-ideas mailing list Python-ideas@python.org htt