[Python-ideas] Assignments in list/generator expressions
Greg Ewing
greg.ewing at canterbury.ac.nz
Thu Apr 14 00:33:46 CEST 2011
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 = ...
> 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.
I don't think there's any need to make a special case here
regarding unpacking. If it's not possible to assign a __doc__
to the object you'll get an exception, and if it works but
gets lost in the unpacking, too bad.
Also I can't see why multiple assignment targets would be a
problem at all -- the same object just gets assigned to all
the targets, including the __doc__.
--
Greg
More information about the Python-ideas
mailing list