Re: Is this a bug?

Discussion in 'Python' started by Ian Kelly, Jul 16, 2013.

  1. Ian Kelly

    Ian Kelly Guest

    On Tue, Jul 16, 2013 at 9:25 AM, Jack Bates <> wrote:
    > Ah, thank you Chris Angelico for explaining how this is like what happens
    > with default arguments to a function and Joshua Landau for pointing out how
    > assignments inside class bodies refer to properties of "self" on the LHS. It
    > makes sense now. Only I'm struggling to find where the behavior is defined
    > in the language reference. Can someone please help point me to where in the
    > language reference this is discussed? I've been hunting through the section
    > on naming and binding:
    >
    > http://docs.python.org/3/reference/executionmodel.html#naming-and-binding


    The documentation appears to be wrong. It says:

    """
    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. This can lead to errors when a name is used within a
    block before it is bound. This rule is subtle. Python lacks
    declarations and allows name binding operations to occur anywhere
    within a code block. The local variables of a code block can be
    determined by scanning the entire text of the block for name binding
    operations.
    """

    But this only applies to function blocks, not the general case. In
    general, I believe it is more accurate to say that a variable is local
    to the block if its name is found in the locals() dict. That normally
    won't be true until the variable has been bound. Any references prior
    to that will look for a global variable.
    Ian Kelly, Jul 16, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John

    Re: BUG? OR NOT A BUG?

    John, Sep 20, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    528
  2. RedEye
    Replies:
    2
    Views:
    560
    Jason Kester
    Dec 13, 2005
  3. Michel Joly de Lotbiniere

    Bug Parade Bug 4953793

    Michel Joly de Lotbiniere, Nov 30, 2003, in forum: Java
    Replies:
    4
    Views:
    623
    Michel
    Dec 2, 2003
  4. DarkSpy
    Replies:
    4
    Views:
    863
    tom_usenet
    Jun 27, 2003
  5. Steve Holden
    Replies:
    1
    Views:
    378
    Behrang Dadsetan
    Jul 2, 2003
Loading...

Share This Page