Skip to content

double-string-fixer will introduce syntax errors for nested f-strings for Python pre-3.12 versions when pre-commit is run by Python 3.12 #971

@XuehaiPan

Description

@XuehaiPan

Thanks for the great tool! It is really convenient to maintain a consistent code style among contributors. I use the double-string-fixer to keep Python strings in a single-quoted format cooperating with black, which prefers double-quoted strings.

Python 3.12 was just released several days ago. It allows users to write arbitrary nested f-strings without changing the quote styles (PEP 701 – Syntactic formalization of f-strings).

# Python 3.11
f'-DPYTHON_INCLUDE_DIR={sysconfig.get_path("platinclude")}'

# Python 3.12
f'-DPYTHON_INCLUDE_DIR={sysconfig.get_path('platinclude')}'  # syntax error in Python 3.11

The pre-commit-hooks are invoked by the Python interpreter which runs pre-commit. When the pre-commit command is installed with Python 3.12, it enables PEP 701 and will introduce syntax errors for Python pre-3.12 versions.

- f'-DPYTHON_INCLUDE_DIR={sysconfig.get_path("platinclude")}'
+ f'-DPYTHON_INCLUDE_DIR={sysconfig.get_path('platinclude')}'

This maybe a problem for a project that supports multiple Python versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions