[Python-ideas] Assignments in list/generator expressions
ncoghlan at gmail.com
Thu Apr 14 03:48:36 CEST 2011
On Thu, Apr 14, 2011 at 8:33 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Nick Coghlan wrote:
>> I have the glimmerings of a rewrite of PEP 3150 kicking around in my
>> skull, that may include restricting it to assignment statements
> Please don't, as that would eliminate a potentially useful
> set of use cases.
> Or at least it would be trying to, but it wouldn't be entirely
> effective, because you would always be able to write
> dummy = something(foo) given:
> foo = ...
Yep, that's why I'm considering just describing the motivation in
terms of assignment, but then expanding it to other cases (including
"pass") to avoid silly workarounds when people decide to use it more
for the local namespace aspect than the "it's like 'def' for arbitrary
assignments" aspect (and "return" and "yield" have a lot in common
with assignment, anyway).
>> Another addition I am considering is the idea of allowing the "given"
>> suite to contain a docstring... This may require
>> disallowing tuple unpacking and multiple assignment targets
> I'm guessing you're thinking that the docstring would be
> assigned to the __doc__ attribute of whatever object the
> RHS expression returns.
Ah, true, that would make a lot of sense. It also generalises nicely
to other cases like "return" and "yield" as well. I'll see if I can
thrash out something sensible along those lines.
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas