[Python-ideas] Short form for keyword arguments and dicts

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Jun 24 01:54:04 CEST 2013


Joshua Landau wrote:

>>> class Foo:
>>>     bar = bar

>  > On 23 June 2013 09:39, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> 
>>Also, it's a somewhat dubious thing to write anyway, since it
>>relies on name lookups in a class scope working dynamically.
>>While they currently do in CPython, I wouldn't like to rely on
>>that always remaining the case.
> 
> Is this not a defined behaviour?

According to the Language Reference, section 4.1, "Naming and binding":

     If a name binding operation occurs anywhere within a code block,
     all uses of the name within the block are treated as references
     to the current block.

No distinction is made there between function bodies and
other kinds of block.

Also in that section,

     A class definition is an executable statement that may use and
     define names. These references follow the normal rules for name
     resolution.

So I would conclude that the above code is technically illegal.

-- 
Greg


More information about the Python-ideas mailing list