pypa / pypa/packaging.python.org

Add recommendation for "escaping" quoted inline script metadata

Open
#1,835 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.7k
Forks
1.7k
Avg merge
3d 12h
Merged PRs (30d)
4

Description

Issue Description

As described in https://github.com/astral-sh/uv/issues/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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the inline script metadata recommendations at packaging.python.org and review the guidance around embedding metadata in Python strings. Add a warning about quoted multiline strings being detected as metadata, include the string-concatenation approach shown in the issue, and confirm the recommendation is clear and accurate.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.