Skip to content

SyntaxError on Python < 3.12: backslash in f-string expression (frictionless/gpkg.py) #197

Description

@jinskeep-morpc

Problem

morpc/frictionless/gpkg.py:264 puts a backslash inside an f-string expression:

name=f"{baseName}-{re.sub(r'\W+', '-', layerName).lower()}",

Python 3.12 allows this (PEP 701). Python 3.10 and 3.11 reject it, so any import of morpc.frictionless fails with:

File ".../morpc/frictionless/gpkg.py", line 264
    name=f"{baseName}-{re.sub(r'\W+', '-', layerName).lower()}",
SyntaxError: f-string expression part cannot include a backslash

pyproject.toml says requires-python = ">=3.10", so this breaks versions the package claims to support.

Impact

This breaks downstream packages too. In morpc-census CI, the Python 3.11 job fails 164 of 337 tests because of this import error, while the 3.12 job passes (failing run).

Suggested fix

Move the re.sub call out of the f-string:

safeLayerName = re.sub(r'\W+', '-', layerName).lower()
...
name=f"{baseName}-{safeLayerName}",

A search of morpc/ turned up no other backslash inside an f-string expression. Adding Python 3.10/3.11 to the CI test matrix would catch this kind of problem next 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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions