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

Difference between _string.formatter_parser in cpython and rustpython #5427

Closed
kaanyalova opened this issue Oct 28, 2024 · 1 comment · Fixed by RustPython/Parser#124
Closed
Labels
A-stdlib C-compat A discrepancy between RustPython and CPython good first issue Good for newcomers

Comments

@kaanyalova
Copy link

The outputs of this script are different between rustpython and cpython

import _string

format_string = "{title[:220]}"


for literal_text, field_name, format_spec, conv in _string.formatter_parser(
    format_string
):
    print(
        f"literal_text: '{literal_text}' field_name: '{field_name}, format_spec: '{format_spec}, conv: {conv}'"
    )

cpython prints correctly:

literal_text: '' field_name: 'title[:220], format_spec: ', conv: None'

while rustpython prints:

literal_text: '' field_name: 'title[, format_spec: '220], conv: None'

this seems to cause issues when using gallery_dl as this is used for formatting file names in some extractors

@kaanyalova kaanyalova added the C-compat A discrepancy between RustPython and CPython label Oct 28, 2024
@youknowone
Copy link
Member

Thank you for the report.

FormatString::parse_spec which is in our https://github.com/RustPython/Parser repository seems to have a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stdlib C-compat A discrepancy between RustPython and CPython good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants