Q about tail recursion

Tim Peters tim_one at email.msn.com
Sun Feb 27 04:29:07 EST 2000


[Tim]
> And if a def is sometimes meant to return a value and
> sometimes not, redesign the code before you drive yourself
> insane <wink>.

[Moshe Zadka]
> I've thought about writing a small utility to warn me about such
> functions, which should be easy enough: either all or none of
> "RETURN_VALUE" opcodes should be preceded by LOAD_CONST of None.
>
> Would such a scheme work?

Seems so, except in a function that explicitly does "return None" as well
as, e.g., "return 42".  That's rare in my experience.  However, I've
detected subtle evidence that our experiences sometimes differ <wink>.
Doing

    none = None
    return none

would be an adequate workaround.

If you write such a utility, I bet PythonWin and IDLE would like to adopt
it!  I expect "do some sanity checks" to become an increasingly popular
feature of the Python IDEs, and I'd  hate to think that tabnanny.py is the
best sanity-checker the community can come up with <wink>.

encouragingly y'rs  - tim






More information about the Python-list mailing list