Skip to content

Add recommendation for "escaping" quoted inline script metadata #1835

Open

Description

@ncoghlan

Issue Description

As described in astral-sh/uv#12303, inline script metadata added naively to a multi-line string will be incorrectly detected as being actual inline script metadata when parsed in accordance with PEP 723 (since the parsing rules are written to be compatible with a basic regex instead of requiring a full Python parser).

https://packaging.python.org/en/latest/specifications/inline-script-metadata/#recommendations should note the problem, and suggest ways to use Python's string quoting flexibility to avoid the misfire.

For example, replacing:

SOURCE_CODE = """
# /// script
# dependencies = ["pydantic", "email-validator"]
# ///
import pydantic

class Model(pydantic.BaseModel):
    email: pydantic.EmailStr

print(Model(email='hello@pydantic.dev'))
"""

with the following compile time string concatenation:

SOURCE_CODE = ("""
"""
"# /// script"
"""
# dependencies = ["pydantic", "email-validator"]
# ///
import pydantic

class Model(pydantic.BaseModel):
    email: pydantic.EmailStr

print(Model(email='hello@pydantic.dev'))
""")

Code of Conduct

  • I am aware that participants in this repository must follow the PSF Code of Conduct.

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