Open
Description
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.
Metadata
Metadata
Assignees
Labels
No labels