Skip to content

Doc: say id() is only useful for existing objects #57412

Closed

Description

@terryjreedy
BPO 13203
Nosy @birkenfeld, @rhettinger, @terryjreedy, @ezio-melotti, @merwok
Files
  • id_unique.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2013-10-12.16:13:49.126>
    created_at = <Date 2011-10-17.17:50:34.768>
    labels = ['docs']
    title = 'Doc: say id() is only useful for existing objects'
    updated_at = <Date 2013-10-12.16:14:53.055>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2013-10-12.16:14:53.055>
    actor = 'python-dev'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2013-10-12.16:13:49.126>
    closer = 'python-dev'
    components = ['Documentation']
    creation = <Date 2011-10-17.17:50:34.768>
    creator = 'terry.reedy'
    dependencies = []
    files = ['32059']
    hgrepos = []
    issue_num = 13203
    keywords = ['patch']
    message_count = 9.0
    messages = ['145743', '145747', '145752', '145766', '146157', '199551', '199557', '199584', '199585']
    nosy_count = 7.0
    nosy_names = ['georg.brandl', 'rhettinger', 'terry.reedy', 'ezio.melotti', 'eric.araujo', 'docs@python', 'python-dev']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue13203'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    Activity

    1. terryjreedy commented on Oct 17, 2011

      @terryjreedy
      MemberAuthor

      Newbies too often do something like (3.2.2, )

      >>> id(getattr(x, 'pop')) == id(x.pop)
      True

      and get confused by the (invalid) result, whereas

      >>> a,b=getattr(x, 'pop'),x.pop
      >>> id(a)==id(b)
      False

      works properly. I think we should add a sentence or two or three to the id() doc, such as

      Since a newly created argument object is either destroyed or becomes inaccessible before the function returns, *id(obj)* is only useful and valid if *obj* exists prior to the call and therefore after its return.
      The value of an expression such as *id(666)== id(667)* is arbitrary and meaningless. The id of the first int object might or might not be reused for the second one.

    2. birkenfeld commented on Oct 17, 2011

      @birkenfeld
      Member

      If we add something at all, it should be much shorter. After all, the current doc already states "unique during its lifetime".

    3. terryjreedy commented on Oct 17, 2011

      @terryjreedy
      MemberAuthor

      I gave a maximum addition. The first sentence may be enough (or even just the second half of it). What people do not get is that the lifetime of new arg objects is the duration of the function call -- and that the output of id for departed objects is uniquely useless and invalid.

    4. rhettinger commented on Oct 17, 2011

      @rhettinger
      Contributor

      I think this is over-explaining an implementation detail and it makes the docs for id() harder to understand.

      Possibly there can be a FAQ entry about identity but the id() function itself is no place to go into the quirks of when new objects are created or destroyed.

      Also, "getting confused" is often a step in the learning process -- it can't be taken out entirely.

    5. ezio-melotti commented on Oct 22, 2011

      @ezio-melotti
      Member

      A FAQ entry sounds good to me.

    6. birkenfeld commented on Oct 12, 2013

      @birkenfeld
      Member

      Suggestion attached.

    7. ezio-melotti commented on Oct 12, 2013

      @ezio-melotti
      Member

      LGTM

      • created and deleted during execution of the id()

      If you want to be more accurate you could say "before and after" instead of "during".

    8. python-dev commented on Oct 12, 2013

      python-devmannequin
      Mannequin

      New changeset 8525cc1f342f by Georg Brandl in branch '2.7':
      Closes bpo-13203: add a FAQ section about seemingly duplicate id()s.
      http://hg.python.org/cpython/rev/8525cc1f342f

    9. python-dev commented on Oct 12, 2013

      python-devmannequin
      Mannequin

      New changeset 0d5de993db66 by Georg Brandl in branch '3.3':
      Closes bpo-13203: add a FAQ section about seemingly duplicate id()s.
      http://hg.python.org/cpython/rev/0d5de993db66

    10. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions