[Python-ideas] Assignments in list/generator expressions
Guido van Rossum
guido at python.org
Wed Apr 13 20:10:43 CEST 2011
On Tue, Apr 12, 2011 at 10:53 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> I have the glimmerings of a rewrite of PEP 3150 kicking around in my
> skull, that may include restricting it to assignment statements (I'm
> not 100% decided on that point as yet - I'll make up my mind as the
> rest of the rewrite takes shape). The reason I am considering such a
> restriction is that the new Rationale section will likely be along the
> following lines:
[...]
Hm. Most of the other simple statements currently mentioned in the PEP
make sense to me as well, e.g. "return X given: ...".
> Another addition I am considering is the idea of allowing the "given"
> suite to contain a docstring, thus providing a way to make it easy to
> attach a __doc__ attribute to arbitrary targets. This may require
> disallowing tuple unpacking and multiple assignment targets when using
> the given clause, or else simply raising a syntax error if a docstring
> is present for an assignment using either of those forms.
I like the idea of allowing a docstring in the given-clause, but I'm
not sure I care to enforce that the docstring is preserved somehow in
the target expression. And then again maybe if it's not preserved it's
not worth mentioning -- it can be considered a no-op just like putting
a "docstring" (really just a comment) in the middle of a block of
code, or e.g. at the top of a loop.
(All in all I think you have mostly managed to confuse me in this
message. At some point I even thought you meant that the body of the
given clause should be limited to definitions...)
--
--Guido van Rossum (python.org/~guido)
More information about the Python-ideas
mailing list