Skip to content

F-strings do not properly pad when ANSI colour codes are included in the input #141535

@Redstone118

Description

@Redstone118

Bug report

Bug description:

#ANSI colour code for red foreground, '\033[31m', and '0'
example_string = "\033[31m0"
print(f"|{ example_string:<3}|")

Produces the following output:
|0|
Which is not padded as would be expected

Removing the colour code however

example_string = "0"
print(f"|{ example_string:<3}|")`

Produces the expected value
|0 |

This leads to misalignment when padding coloured content

CPython versions tested on:

3.13

Operating systems tested on:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions