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

Hexadecimal id in reprs #66230

Closed
serhiy-storchaka opened this issue Jul 22, 2014 · 6 comments
Closed

Hexadecimal id in reprs #66230

serhiy-storchaka opened this issue Jul 22, 2014 · 6 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 22031
Nosy @vstinner, @stevendaprano, @serhiy-storchaka
Files
  • repr_hex_id.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/serhiy-storchaka'
    closed_at = <Date 2014-07-22.09:17:52.341>
    created_at = <Date 2014-07-22.08:50:41.985>
    labels = ['type-bug', 'library']
    title = 'Hexadecimal id in reprs'
    updated_at = <Date 2014-07-22.11:52:11.415>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2014-07-22.11:52:11.415>
    actor = 'vstinner'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2014-07-22.09:17:52.341>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2014-07-22.08:50:41.985>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['36025']
    hgrepos = []
    issue_num = 22031
    keywords = ['patch']
    message_count = 6.0
    messages = ['223647', '223648', '223652', '223653', '223660', '223662']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'steven.daprano', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue22031'
    versions = ['Python 3.5']

    @serhiy-storchaka
    Copy link
    Member Author

    Default repr of an instance looks as:

    >>> object()
    <object object at 0xb71a14a8>

    Many specialized reprs follow a pattern <... at {hexadecimal id}...>. But there are few deviations:

    1. Reprs of WeakValueDictionary and WeakKeyDictionary in the weakref module output decimal id.

    2. reprlib and reprs of CDLL in the ctypes module and DateTime and MultiCall in the xmlrpc.client module output hexadecimal id but without the "0x" prefix.

    Proposed patch makes these cases to conform with other reprs.

    @serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jul 22, 2014
    @vstinner
    Copy link
    Member

    The patch looks good to me.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 22, 2014

    New changeset 4cef7b0ec659 by Serhiy Storchaka in branch 'default':
    Issue bpo-22031: Reprs now always use hexadecimal format with the "0x" prefix
    http://hg.python.org/cpython/rev/4cef7b0ec659

    @serhiy-storchaka
    Copy link
    Member Author

    Thanks Victor. Applied only in default because this issue is too minor.

    @stevendaprano
    Copy link
    Member

    Many specialized reprs follow a pattern <... at {hexadecimal id}...>.
    But there are few deviations:
    [...]
    Proposed patch makes these cases to conform with other reprs.

    I oppose making this change. The exact format of this generic repr of
    instances is not a part of Python's API, and we should not encourage
    people to think that it must always follow the same pattern or rely on
    that pattern.

    Changing the repr risks breaking doctests. That *might* be acceptable if
    there was some obvious benefit to the change, e.g. changing from some
    generic <whatever at some_id> to a nicer, more useful display. But to
    risk breaking doctests just for consistency with other generic displays
    when that consistency has never been promised is not worth it.

    @vstinner
    Copy link
    Member

    Changing the repr risks breaking doctests.

    That's why the change was only done in Python 3.5. To port your application to Python 3.5, you can modify you doctests to use "..." (ellipsis option of doctests).

    That *might* be acceptable if there was some obvious benefit
    to the change,

    It's better to have consistent representation of objects. Low-level debuggers like gdb uses hexadecimal, not decimal. I'm regulary using gdb, and having the memory address in hexadecimal helps.

    By the way, you should never rely on the (exact) representation in your unit tests :-)

    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants