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

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

Open
1 task done
ncoghlan opened this issue Mar 21, 2025 · 0 comments
Open
1 task done

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

ncoghlan opened this issue Mar 21, 2025 · 0 comments

Comments

@ncoghlan
Copy link
Member

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='[email protected]'))
"""

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='[email protected]'))
""")

Code of Conduct

  • I am aware that participants in this repository must follow the PSF Code of Conduct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant