Skip to content

PythonFormat ignores zero-padding for integer formats like %04d #12

Description

@ilka-schulz

Description

dynfmt::PythonFormat does not appear to apply zero-padding when formatting integers. For example, formatting an integer with %04d produces 42 instead of 0042.

Reproduction

use dynfmt::{Format, PythonFormat};

fn main() {
    let result = PythonFormat
        .format("%04d", &[42])
        .unwrap();

    assert_eq!(result, "0042");
}
  • expected behavior: 0042
  • actual behavior: 42

Notes

The parser appears to recognize both the field width and the 0 flag, but these formatting options do not seem to be applied when the value is eventually formatted.

Since %04d is valid Python-style % formatting as well as standard printf-style formatting, I would expect PythonFormat to honor the requested width and zero-padding.

It looks like other formatting options stored in the parsed argument specification, such as width/alignment/precision, may potentially be affected by the same issue.

AI Disclaimer

I found this issue myself when using dynfmt on a project. However, I did let ChatGPT write the content of this issue to save time.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions