Skip to content

format() ignores leading 0 when _ is used #112876

@doko42

Description

@doko42

Bug report

Bug description:

seen with 3.11 and 3.12, trunk not tested

>>> i = int.from_bytes(b'11112345', 'little')
>>> hex(i)
'0x3534333231313131'
>>> format(i, '064b')
'0011010100110100001100110011001000110001001100010011000100110001'
>>> format(i, '064_b')
'11_0101_0011_0100_0011_0011_0011_0010_0011_0001_0011_0001_0011_0001_0011_0001'

Expected output for the last line:

'0011_0101_0011_0100_0011_0011_0011_0010_0011_0001_0011_0001_0011_0001_0011_0001'

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions