[Python-3000] Special object to return from functions that return only None
Ian Bicking
ianb at colorstudy.com
Wed Apr 19 21:23:29 CEST 2006
Guido van Rossum wrote:
> On 4/19/06, Edward C. Jones <edcjones at comcast.net> 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".
>
>
> Apart from assignment, None already has very few methods, so it
> already has this purpose.
>
> Trapping this on assignment would require *every* assignment (and
> argument passing, and who knows what else) to pay for the overhead for
> an additional specific check. I don't think that's feasible.
It also makes pass-through decorators and delegates harder. At least if
you make it any stronger than what None already is. None doesn't do
anything, but you can pass it around. You could disallow the passing
around of a UseForbidden object, but then you need special ways of
saying things like "run this function, give me the return value, and
really this time it's okay if it is a UseForbidden object".
--
Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
More information about the Python-3000
mailing list