[Python-Dev] new draft of PEP 227

M.-A. Lemburg mal@lemburg.com
Thu, 14 Dec 2000 16:02:33 +0100


Jeremy Hylton wrote:
> 
> >>>>> "MAL" == M -A Lemburg <mal@lemburg.com> writes:
> 
>   MAL> Jeremy Hylton wrote:
>   >>
>   >> I've got a new draft of PEP 227.  The terminology and wording are
>   >> more convoluted than they need to be.  I'll do at least one
>   >> revision just to say things more clearly, but I'd appreciate
>   >> comments on the proposed spec if you can read the current draft.
> 
>   MAL> The PEP doesn't mention the problems I pointed out about
>   MAL> breaking the lookup schemes w/r to symbols in methods, classes
>   MAL> and globals.
> 
> I believe it does.  There was some discussion on python-dev and
> with others in private email about how classes should be handled.
> 
> The relevant section of the specification is:
> 
>     If a name is used within a code block, but it is not bound there
>     and is not declared global, the use is treated as a reference to
>     the nearest enclosing function region.  (Note: If a region is
>     contained within a class definition, the name bindings that occur
>     in the class block are not visible to enclosed functions.)

Well hidden ;-)

Honestly, I think that you should either make this specific case
more visible to readers of the PEP since this single detail would
produce most of the problems with nested scopes.

BTW, what about nested classes ? AFAIR, the PEP only talks about
nested functions.

>   MAL> Please add a comment about this to the PEP + maybe the example
>   MAL> I gave in one the posts to python-dev about it. I consider the
>   MAL> problem serious enough to limit the nested scoping to lambda
>   MAL> functions (or functions in general) only if that's possible.
> 
> If there was some other concern you had, then I don't know what it
> was.  I recall that you had a longish example that raised a NameError
> immediately :-).

The idea behind the example should have been clear, though.

x = 1
class C:
   x = 2
   def test(self):
       print x
  
-- 
Marc-Andre Lemburg
______________________________________________________________________
Company:                                        http://www.egenix.com/
Consulting:                                    http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/