Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
terryjreedy opened this issue Oct 17, 2011 · 9 comments
Closed

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

terryjreedy opened this issue Oct 17, 2011 · 9 comments
Assignees
Labels
docs Documentation in the Doc dir

Comments

@terryjreedy
Copy link
Member

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']

    @terryjreedy
    Copy link
    Member Author

    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.

    @terryjreedy terryjreedy added the docs Documentation in the Doc dir label Oct 17, 2011
    @birkenfeld
    Copy link
    Member

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

    @terryjreedy
    Copy link
    Member Author

    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.

    @rhettinger
    Copy link
    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.

    @rhettinger rhettinger assigned rhettinger and unassigned docspython Oct 17, 2011
    @ezio-melotti
    Copy link
    Member

    A FAQ entry sounds good to me.

    @birkenfeld
    Copy link
    Member

    Suggestion attached.

    @ezio-melotti
    Copy link
    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".

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 12, 2013

    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

    @python-dev python-dev mannequin closed this as completed Oct 12, 2013
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 12, 2013

    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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants