Need help with Python scoping rules

kj no.email at please.post
Wed Aug 26 17:14:27 CEST 2009


In <mailman.447.1251297107.2854.python-list at python.org> Dave Angel <davea at ieee.org> writes:

>Thanks for diluting my point.  The OP is chasing the wrong problem.  Who 
>cares whether a class initializer can call a method, if the method 
>doesn't meet its original requirements, to be callable outside the class?

>And the arguments about how recursion is restricted are ridiculous.  
>Nothing wrong with a method calling itself, once it's got a proper 
>signature.  You just have to make the call agree with the signature.  
>The problem is only that the method may not be actually called until the 
>class definition is complete.

As I described at length in another reply, the function in question
is not intended to be "callable outside the class".  And yes,
recursive functions in Python *are* restricted in ways that
non-recursive functions aren't.  The examples I've posted prove
this point unambiguously.

At this point the only defense for this restriction is to claim
that it is somehow negligible.  But I disagree.  It's easy to come
up with equally negligible, and equally indefensible, restrictions
to the language would be found quite unacceptable by most users.
E.g. suppose that Python's specification prohibited the use of
upper case X in an identifier.  That's certainly a negligible
restriction: it is not harder at all to write great software without
the services of the letter X than with them.  Still, I think most
users would find this restriction infuriatingly idiotic.  Which
pretty much captures what I feel about Python's prohibition of
recursive functions within class statements.

kynn



More information about the Python-list mailing list