On Mon, Jan 17, 2022 at 7:36 AM John Sturdy <jcg.stu...@gmail.com> wrote:

> For example, it bugs me that you can write:
>
> if a:
>     b = f(x)
> else:
>     b = g(y)
>
> and get the same variable 'b' from it in the lines of code following that,
> regardless of which path was taken.
>

Really? But that is a VERY common pattern. In fact, I would find it very
hard to write an enormous amount of code without it. and what if you
refactored that to be:

b = f(x) if a else g(x)

Do you really want that to mean something different ?!?!

Or are what you are getting at that if you want those two forms to be the
same, then you'd need to do something like:

b = None
if a:
    b = f(x)
else:
    b = g(y)

Which means essentially that you'd like to have to  declare names in order
to ues them outside the very narrowest of scopes.

But this is not how Python works, and it never has, it would be a really
massive change, and I for one, would not like it :-(

Also -- which blocks would create a new scope? All of them:

for (else)
while (else)
with
if (elif, else)
try (except, else)

I guess what I'm getting at is that I'm pretty sure I would find this
useful rarely, and an annoyance often.

- CHB



-- 
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VJIQXNGBSQB4C6WZIY6VA2BAFCDWZVQL/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to