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

Not matched behavior within printf style bytes formatting #73186

Closed
wooyoo mannequin opened this issue Dec 17, 2016 · 9 comments
Closed

Not matched behavior within printf style bytes formatting #73186

wooyoo mannequin opened this issue Dec 17, 2016 · 9 comments
Assignees
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@wooyoo
Copy link
Mannequin

wooyoo mannequin commented Dec 17, 2016

BPO 29000
Nosy @bitdancer, @ethanfurman, @serhiy-storchaka
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Files
  • bytes-format-oct-alt-zero.patch
  • 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 2016-12-17.20:18:12.502>
    created_at = <Date 2016-12-17.13:41:04.667>
    labels = ['interpreter-core', 'type-bug', '3.7']
    title = 'Not matched behavior within printf style bytes formatting'
    updated_at = <Date 2017-03-31.16:36:28.705>
    user = 'https://bugs.python.org/wooyoo'

    bugs.python.org fields:

    activity = <Date 2017-03-31.16:36:28.705>
    actor = 'dstufft'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-12-17.20:18:12.502>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2016-12-17.13:41:04.667>
    creator = 'woo yoo'
    dependencies = []
    files = ['45943']
    hgrepos = []
    issue_num = 29000
    keywords = ['patch']
    message_count = 9.0
    messages = ['283485', '283486', '283488', '283489', '283491', '283499', '283502', '283513', '283514']
    nosy_count = 6.0
    nosy_names = ['r.david.murray', 'docs@python', 'ethan.furman', 'python-dev', 'serhiy.storchaka', 'woo yoo']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29000'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @wooyoo
    Copy link
    Mannequin Author

    wooyoo mannequin commented Dec 17, 2016

    Per the documentation,"The alternate form causes a leading octal specifier ('0o') to be inserted before the first digit", However the actual behavior didn't conform to the principle.

    Code:

    >>b'%#07o' % 34

    Output: b'0000o42'

    @wooyoo wooyoo mannequin added the docs Documentation in the Doc dir label Dec 17, 2016
    @wooyoo wooyoo mannequin assigned docspython Dec 17, 2016
    @wooyoo
    Copy link
    Mannequin Author

    wooyoo mannequin commented Dec 17, 2016

    @bitdancer
    Copy link
    Member

    The documentation matches the behavior. In this context "the first digit" is the 4. The leading zeros are the pad fill. Now, whether this is *useful* behavior or not is a separate question :) And yes, the docs could be clarified on this point either way.

    @wooyoo
    Copy link
    Mannequin Author

    wooyoo mannequin commented Dec 17, 2016

    Make a slight change to my code, which becomes b'%#07x' % 34, the weird situation appears.

    @serhiy-storchaka
    Copy link
    Member

    This is not documentation issue, but a bug in formatting octals in bytes.

    >>> '%#07x' % 123
    '0x0007b'
    >>> b'%#07x' % 123
    b'0x0007b'
    >>> '%#07o' % 123
    '0o00173'
    >>> b'%#07o' % 123
    b'000o173'
         ^

    @serhiy-storchaka serhiy-storchaka added interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error and removed docs Documentation in the Doc dir labels Dec 17, 2016
    @serhiy-storchaka
    Copy link
    Member

    Proposed patch fixes this inconsistency.

    @bitdancer
    Copy link
    Member

    OK, that makes sense. Patch looks good to me.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 17, 2016

    New changeset 96d728c14267 by Serhiy Storchaka in branch '3.5':
    Issue bpo-29000: Fixed bytes formatting of octals with zero padding in alternate
    https://hg.python.org/cpython/rev/96d728c14267

    New changeset 29c9c414c310 by Serhiy Storchaka in branch '3.6':
    Issue bpo-29000: Fixed bytes formatting of octals with zero padding in alternate
    https://hg.python.org/cpython/rev/29c9c414c310

    New changeset 4e55e011dd80 by Serhiy Storchaka in branch 'default':
    Issue bpo-29000: Fixed bytes formatting of octals with zero padding in alternate
    https://hg.python.org/cpython/rev/4e55e011dd80

    @serhiy-storchaka
    Copy link
    Member

    Thanks David.

    @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
    3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants