[Python-3000] Special object to return from functions that return only None

Guido van Rossum guido at python.org
Wed Apr 19 13:24:16 CEST 2006


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.

I also don't think it's all that important as a feature, so I wouldn't
want to go to length to implement this. Unless you can show a working
patch that doesn't affect performance I consider this idea rejected
(but thanks for throwing it out anyway -- this is the time to generate
and quickly reject lots of ideas!).

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list