[Python-Dev] Is PEP 572 really the most effective way to solve the problems it's targeting?

Stephen J. Turnbull turnbull.stephen.fw at u.tsukuba.ac.jp
Thu Apr 26 07:35:20 EDT 2018


Steven D'Aprano writes:
 > On Wed, Apr 25, 2018 at 09:36:31PM -0500, Ryan Gonzalez wrote:

 > > Now, what's the common theme here? **Declarations should be separate from 
 > > expressions.**
 > 
 > Declarations and assignments are not the same thing.

Ryan mostly meant "initialization" rather than "declaration", I
suspect.  In C's for() statement, the first clause in parentheses is
initialization, the third is assignment.

FWIW, I had been thinking the same thing (that what is really wanted
is initialization clauses in loop statements) but had no concrete
suggestions.  Now I too have warmed to the binding expression approach
(partly because Guido has, so I'm preparing for the inevitable :^),
mostly because of Tim's "humorous observation" about use in printf
debugging.  The fact that there is this use case independent of block
variable initialization (ie, in a loop or if statement) is quite
attractive to me.

It's true, as I think Antoine pointed out, that it's easy enough to
define a wrapper function that prints a value and returns it.  But
that's not as flexible, and if you have more than one variable to
"watch", you either need an argument to the wrapper to provide the
variable's name, or different functions for different variables.



More information about the Python-Dev mailing list