[2.3] object does not appear to be a reserved word

Discussion in 'Python' started by Daniel Klein, Sep 6, 2003.

  1. Daniel Klein

    Daniel Klein Guest

    Is it potentially dangerous to use the variable 'object' in code?

    Thanks,
    Daniel Klein
     
    Daniel Klein, Sep 6, 2003
    #1
    1. Advertising

  2. Daniel Klein

    John Roth Guest

    "Daniel Klein" <> wrote in message
    news:...
    > Is it potentially dangerous to use the variable 'object' in code?


    "object" is, I believe, a built-in type in the builtins namespace.
    As such, you can shadow it so it's inacessable. However,
    the only place were that could cause problems is if you
    use it as an identifier at the module level. I think.

    John Roth
    >
    > Thanks,
    > Daniel Klein
     
    John Roth, Sep 6, 2003
    #2
    1. Advertising

  3. John Roth wrote:

    >"Daniel Klein" <> wrote in message
    >news:...
    >
    >
    >>Is it potentially dangerous to use the variable 'object' in code?
    >>
    >>

    >
    >"object" is, I believe, a built-in type in the builtins namespace.
    >As such, you can shadow it so it's inacessable. However,
    >the only place were that could cause problems is if you
    >use it as an identifier at the module level. I think.
    >
    >

    Another place: errors in (copied) code which get silently ignored
    because of the presence of the "object" type.

    For instance, if you cut-and-past a few lines of (older, particularly
    pre-2.2) code which uses the variable "object" into a new situation
    which uses "item" (or whatever), the older code will often seem to be
    functioning properly because it uses the type "object" as an instance,
    instead of raising a NameError. Tends to result in subtle bugs, but not
    likely enough to warrant breaking all the old code that used "object" as
    an identifier by making it a keyword.

    To answer the original question, yes, it's somewhat dangerous to use
    "object" as an identifier in code. It's approximately equally dangerous
    to use "str", "list", or "tuple" as an identifier. It's just that the
    temptation to use "object" is greater when you're doing a lot of
    polymorphic programming, and you'll find older code (pre 2.2) using it
    without any concern whatsoever (because there was no object type back
    then to cause a problem).

    Each new built-in causes the same problem, it's just that "object" is so
    fundamental an idea (both as a built-in and an identifer) that it's
    probably the most likely source of such low-level conflicts going
    forward. (e.g. enumerate, or zip are used in code once in a while, but
    compared to "object" are fairly uncommon choices for an identifier).

    Enjoy,
    Mike

    _______________________________________
    Mike C. Fletcher
    Designer, VR Plumber, Coder
    http://members.rogers.com/mcfletch/
     
    Mike C. Fletcher, Sep 6, 2003
    #3
  4. Daniel Klein

    Terry Reedy Guest

    "Daniel Klein" <> wrote in message
    news:...
    > Is it potentially dangerous to use the variable 'object' in code?


    Yes, it is potentially dangerous to use any of the names in the
    builtin module. It is disrecommended for posted/public code without
    good reason (intentional override).

    TJR
     
    Terry Reedy, Sep 6, 2003
    #4
  5. Daniel Klein

    Daniel Klein Guest

    Thanks John., that's what I suspected.

    This particular module uses the variable 'object' as an argument to
    several methods and functions. I'll probably change it anyway, but I
    was just curious as to why it seemed to run ok.

    Thanks again for the confirmation.

    Dan

    On Sat, 6 Sep 2003 15:47:07 -0400, "John Roth"
    <> wrote:

    >
    >"Daniel Klein" <> wrote in message
    >news:...
    >> Is it potentially dangerous to use the variable 'object' in code?

    >
    >"object" is, I believe, a built-in type in the builtins namespace.
    >As such, you can shadow it so it's inacessable. However,
    >the only place were that could cause problems is if you
    >use it as an identifier at the module level. I think.
    >
    >John Roth
    >>
    >> Thanks,
    >> Daniel Klein

    >
     
    Daniel Klein, Sep 7, 2003
    #5
    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. metaperl
    Replies:
    32
    Views:
    924
    NickC
    Sep 15, 2006
  2. Delaney, Timothy (Tim)
    Replies:
    10
    Views:
    672
    Jason
    Sep 14, 2006
  3. Steve Holden
    Replies:
    0
    Views:
    398
    Steve Holden
    Sep 13, 2006
  4. globalrev
    Replies:
    8
    Views:
    285
    Terry Reedy
    May 5, 2008
  5. Replies:
    3
    Views:
    170
    osmium
    Nov 6, 2013
Loading...

Share This Page