[Python-3000] Special object to return from functions that return only None
Brian Harring
ferringb at gmail.com
Wed Apr 19 14:55:42 CEST 2006
On Tue, Apr 18, 2006 at 09:41:20PM -0400, Edward C. Jones wrote:
> Wild idea.
>
> When I was a newbie, I repeatedly make the mistake of writing
>
> alist = alist.sort()
>
> I suggest a singleton object "UseForbidden" ("Py_UseForbidden" in C).
> "UseForbidden" can be used only to return from a function. Any other
> attempt to use "UseForbidden" raises an exception. The incorrect code
> above would give the error message "cannot assign to result of function".
Not to beat the horse a bit further, but...
This would also have the unfortunate side affect of forbidding
snippets like-
groupped_lists = generate_list_of_lists()
[l.sort() for l in groupped_lists]
Yes, it's lazy (could use a for loop doesn't generate a list), but the
short hand there is common enough, as is the map equiv.
Rough guess, to properly handle above (ie, support it while
disallowing assignment to vars) requires tracing back the
assignment- no longer is it just "am I assigning to a var", it's now
"am I being handed to a var that is going to go away immediately"
which is far uglier/nastier.
My interpretation at least, either way -1 (especially if it kills off
the short hand) :)
~harring
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-3000/attachments/20060419/3b86b695/attachment.pgp
More information about the Python-3000
mailing list