Skip to content

Script metadata parser silently accepts duplicate script blocks #18617

@themavik

Description

@themavik

Summary

ScriptTag::parse in uv-scripts/src/lib.rs finds the first # /// script block using FINDER.find(contents) (line ~500) and returns its TOML. It never checks whether the file contains a second # /// script block after the first one closes.

PEP 723 says tools MUST error when a script contains multiple embedded metadata blocks. Right now uv silently uses whichever one comes first and ignores any others.

A file like this should be rejected:

# /// script
# dependencies = ["requests"]
# ///

print("hi")

# /// script
# dependencies = ["flask"]
# ///

Instead uv picks requests and quietly drops flask.

Platform

Linux x86_64 (code-level, platform-independent)

Version

latest main (code read from HEAD)

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatibilityCompatibility with a specification or another toolerror messagesMessaging when something goes wrong

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions